-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-types.py
92 lines (61 loc) · 2.18 KB
/
data-types.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
#Python Data Types Tasks
#1- Wich is the differences between ‘ ’ “ ” ‘’’ ‘’’
'''
a- Single & Double Quotes
Enclose strings. Either single or double quotes are fine.
Use single quotes as enclosing quotes to eliminate the need of escaping double quotes in a string, and vice versa.
b- Triple Quotes
Enclose strings containing both single and double quotes such that no escaping is needed.
Enclose multi-line strings.
'''
#2- Create a string with the name ‘mystro’
print('------------------------------------')
name = 'mystro'
#3- Make the string letters capital
print('------------------------------------')
name = 'mystro'
print(name.upper())
#4- Create a list of values from 10 to 20
print('------------------------------------')
l = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
#5- Add 30 to the end of the list
print('------------------------------------')
l = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
l.append(30)
print(l)
#6- Add 40 as the second element of the list
print('------------------------------------')
l = [10,11,12,13,14,15,16,17,18,19,20]
l.append(30)
l.insert(1,40)
print(l)
#7- Print how many elements in the list
print('------------------------------------')
l = [10,11,12,13,14,15,16,17,18,19,20]
l.append(30)
l.insert(1,40)
print(len(l))
#8- replace the second element in the list with 100
print('------------------------------------')
l=[10,11,12,13,14,15,16,17,18,19,20]
l[1] = 100
print(l)
#9- Create a tuple with values from 1 to 5
print('------------------------------------')
t = (1, 2, 3, 4, 5)
#10- Can we add 10 to the end of the tuple?
print('------------------------------------')
# no, we can not
#11- Create a dict of value Mahmoud:28 , ahmed:30
print('------------------------------------')
d = {"Mahmod": 28, "ahmed": 30}
#12- Print Mahmoud age from the dict
print('------------------------------------')
d = {"Mahmod": 28, "ahmed": 30}
print(d['Mahmod'])
#13- What is the differences between mutable and immutable data types ?
print('------------------------------------')
'''
An object whose internal state can be changed is mutable.
On the other hand, immutable doesn't allow any change in the object once it has been created.
'''