forked from kal179/Beginners_Python_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuplesExample.py
More file actions
29 lines (21 loc) · 562 Bytes
/
tuplesExample.py
File metadata and controls
29 lines (21 loc) · 562 Bytes
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
# Creating tuples
# Tuples are used to store 2-d grids and fixed values
# tuples are immutable that means they cant be changed
tupA = () # Empty tuple
print(tupA)
c = 12,56,78
tupC = tuple(c) # tuple() is built-in
print(tupC)
x,y,z = (12,45,42)
a = x,y,z
print(a)
print(type(a))
# Accessing items in tuples
print(tupC[0])
print(a[1])
print(tupC[2],'\n')
# tuples cant be reassigned
# tupC[1] = 18 # uncomment this line to see the error this should cause a error 'TypeError'
# iterating through tuples
for x in tupC:
print(x)