-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchap 20_40.py
93 lines (70 loc) · 1.96 KB
/
chap 20_40.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# chapter 20 - 40 & assignment no: 4
# Touple immutable list/array
newToupleArray = (11, 22, 33, 44, 55)
print(newToupleArray)
print(newToupleArray[2])
print(newToupleArray.__len__())
name = str(input("Enter Your Name:")) # Type casting you can use int str,float
print('Hello' + ' ' + name)
age = int(input("Enter Your age: "))
print(age + 5)
name = "TaLha"
print(name.upper()) # Change string to upper case
print(name.lower()) # Change string to lower case
print(name.title()) # change only the first character of word into uppercase
Data = {
"name": "talha",
"age": 22,
5: 88
} # just like object in javascript
print(Data)
# how to access that field of object/list also called dictionary in Python
print(Data["age"])
print(Data[5]) # a number can be a key
Data["city"] = "karachi"
print(Data)
del Data["age"]
print(Data)
for value in Data.values(): # to print the Value of keys
print(value)
for valueOfKey in Data.keys(): # to print the Keys of the values
print(valueOfKey)
for eachKey, eachValue in Data.items(): # To print both key and value we use this
print("The key is " + str(eachKey) + " and the value is " + str(eachValue))
# List of Dictionaries aka Array of object same sas Javascript object and array
arrayOfObjects = [
{
"name": "hello",
"age": 13
},
{
"name": "world",
"age": 15
}
]
print(arrayOfObjects)
# object containing array
arrayOfObjects.append({"numbers": [5555.54, 54, 53, 77]})
print(arrayOfObjects)
# You can also create object of objects
objectOfObjects = {
0:{
"name": "Talha Javed",
"age": "22",
},
1:{
"name": "Python",
"age": "8",
},
}
print(objectOfObjects)
# assignment no: 4
person = {'firstName': 'Talha','lastName': 'Javed','age': 22}
print(person)
person ["qualification"]="bachlors"
print(person)
del person['age']
print(person)
def favorite_book(i):
print("Hii " + i)
favorite_book(str(input("Enter Your Name:")))