Skip to content

Commit 0f5340d

Browse files
committed
tuples in python
1 parent 3c882db commit 0f5340d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tupleOperations.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
__author__ = 'Avinash'
2+
3+
tup = ('abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87')
4+
5+
# prints the length of the tuple
6+
print('\ntuple: ', tup)
7+
print('Length of the tuple is : ', len(tup))
8+
9+
# Slicing
10+
# shows only items starting from 0 upto 3
11+
print('\ntuple: ', tup)
12+
print('tuple showing only items starting from 0 upto 3\n', tup[:3])
13+
14+
# shows only items starting from 4 to the end
15+
print('\ntuple: ', tup)
16+
print('tuple showing only items starting from 4 to the end\n', tup[4:])
17+
18+
# shows only items starting from 2 upto 6
19+
print('\ntuple: ', tup)
20+
print('tuple showing only items starting from 2 upto 6\n', tup[2:6])
21+
22+
# reverse all items in the tuple
23+
print('\ntuple: ', tup)
24+
print('tuple items reversed \n', tup[::-1])
25+
26+
# removing whole tuple
27+
del tup
28+
29+
tup_0 = ("ere", "sad")
30+
tup_1 = ("sd", "ds")
31+
print('\nfirst tuple: ', tup_0)
32+
print('second tuple: ', tup_1)
33+
tup = tup_0 + tup_1
34+
print('Concatenation of 2 tuples \n', tup)

0 commit comments

Comments
 (0)