1
+ def main ():
2
+ myList = [1 , 2 , 3 , 4 , 5 ] # this is a list. Initialized by square brackets []
3
+ myList [4 ] = 7 # list are mutable. This means that you can change their content after initialization.
4
+
5
+ for i in myList :
6
+ print ("Value in list : " + str (i ))
7
+
8
+ myTuple = (1 , 2 , 3 , 4 , 5 ) # this is a tuple. Initialized by round brackets ( )
9
+
10
+ for i in myTuple :
11
+ print ("Value in tuple: " + str (i ))
12
+
13
+ # myTuple[4] = 8 # Tuples are immutable. Running this command will throw an error.
14
+
15
+ # Tuples preferred unless you know for sure that you have to change the values.
16
+
17
+ oneArgRange = range (5 ) # this call only gives the start parameter to range
18
+ for i in oneArgRange :
19
+ print ("value in one argument range : " + str (i ))
20
+
21
+ twoArgRange = range (5 , 10 ) # this call gives the start and end parameter to range
22
+ for i in twoArgRange :
23
+ print ("value in two argument range : " + str (i ))
24
+
25
+ fullArgRange = range (5 , 50 , 5 ) # this call gives start, end and the step parameter
26
+ for i in fullArgRange :
27
+ print ("value in complete argument range : " + str (i ))
28
+
29
+ # end parameter values are non inclusive in range.
30
+ # range is also immutable
31
+ listFromRange = list (range (1 , 100 , 10 )) # mutable lists can be made from immutable range
32
+ listFromRange [2 ] = 0
33
+ for i in listFromRange :
34
+ print ("Value in List made from range : " + str (i ))
35
+
36
+ # Dictionaries are a structure of key value pairs and are mutable
37
+
38
+ myDict = {'keyOne' : 1 , 'keyTwo' : 2 , 'keyThree' : 3 , 'keyFour' : 4 , 'keyFive' : 5 }
39
+
40
+ myDict ['keyThree' ] = 33
41
+ for key , value in myDict .items () :
42
+ print ("Printing dictionary key value pairs : " + key + " " + str (value ))
43
+
44
+ main ()
0 commit comments