-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondDemo.py
More file actions
56 lines (39 loc) · 1.18 KB
/
SecondDemo.py
File metadata and controls
56 lines (39 loc) · 1.18 KB
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
#LIST
# #This is a List, this data type allows multiple values and can have different data types
values = [1,2,"tripti",4,5]
#printing using single index
print(values[0]) #prints 1
print(values[2]) #prints tripti
print(values[3]) #prints 4
print(values[-1]) #reference to the last index, prints 5
#printing a sequence of items in the given list
print(values[1:3]) #prints 2 and tripti because this only prints till n-1 item ie in this case 3-1
print(values)
#inserting another value to values list
values.insert(3,"Singh")
print(values)
#insert another item at the end of the list
values.append("End")
print(values)
#updating value
values[2] = "Tripti"
#deleting a value
del values[0]
print(values)
#Tuple
#This is a Tuple, this data type allows multiple values and can have different data types
#Tuple is similar to List, but it is Immutable
val = (1, 2, "Tripti",4.5)
print(val[1])
# val[2] = "Tripti"
#this will fail with error - TypeError: 'tuple' object does not support item assignment
#Dictionary
di1 ={"a":2,4:"bcd","c":"Hello World"}
print(di1[4])
print(di1["c"])
di2 ={}
di2["First Name"]="Tripti"
di2["Last Name"]="Singh"
di2["Gender"]="Female"
print(di2)
print(di2["Last Name"])