forked from yubarajpoudel/python-learn-step-by-step
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuples.py
More file actions
76 lines (46 loc) · 1.18 KB
/
tuples.py
File metadata and controls
76 lines (46 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
57
58
59
60
61
62
# tuple is moreover like the list
# list is basically used for homogenous data type
# tuple is used for hetergenous data type
a = ('test', 1, 'sample')
# for accessing the data from the tuple
for data in a:
print(data)
# Why we use the tuple ?
# tuples are immutable
# for constants list we use the tuple
# for declaring the tuple with single item it is bit tricky
a = ('hello',)
print(a)
# change the value in the tuple
b = (1,5,6,7,8,)
print("orginal b = {}".format(b))
# b[3] = 9
# print(b)
# this will throw the error because tuple doesnot support the assignment
c = ((3,4), 5, 7, (3,5,6,7))
print(c[3][2])
# checking the size
print(len(c))
# tupe concatenation
e = a+b
print(e)
# slice the tuple
# for eg
names = ('ram','sita','hari','laxmi','shiva', 'parbati')
# slice the names from second index value to 4th index value
print(names[2:4])
print(names[-3:])
# we can declare the tuple without bracket aswell
test = 3,4,5,6
print(type(test))
# set
test = {"hello", "set"}
print(test)
print(type(test))
test.add("hello")
print(test)
# other way of defining set
weekDay = set(["Sunday", "Monday", "Tuesday"])
print(type(weekDay))
for weekName in weekDay:
print(weekName)