-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuple.py
52 lines (29 loc) · 839 Bytes
/
tuple.py
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
# Created by Elshad Karimov on 23/04/2020.
# Copyright © 2020 AppMillers. All rights reserved.
# How to create a Tuple?
newTuple = ('a', 'b', 'c', 'd', 'e')
newTuple1 = tuple('abcde')
print(newTuple1)
# Access Tuple elements
print(newTuple[0])
# Traverse through tuple
for i in newTuple:
print(i)
for index in range(len(newTuple)):
print(newTuple[index])
# How to search for an element in Tuple?
print('a' in newTuple)
def searchInTuple(pTuple, element):
for i in pTuple:
if i == element:
return pTuple.index(i)
return 'The element does not exist'
print(searchInTuple(newTuple, 'a'))
# Tuple Operations / Functions
myTuple = (1,4,3,2,5)
myTuple1 = (1,2,6,9,8,7)
print(myTuple + myTuple1)
print(myTuple * 4)
print(2 in myTuple1)
myTuple1.count(2)
myTuple1.index(2)