-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuple_op.py
More file actions
38 lines (26 loc) · 740 Bytes
/
tuple_op.py
File metadata and controls
38 lines (26 loc) · 740 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
30
31
32
33
34
35
36
37
38
# Creating a tuple
input = ('IBN', 5, 23.6)
# unpacking tuple
share_name, count, price = input
# total_share_cost = input[1] * input[2]
total_share_cost = count * price
print('Total Share cost : ', total_share_cost)
# tuples are immutable
# input[1] = 6
# TypeError: 'tuple' object does not support item assignment
def test_tuple():
print(inputs)
for name, age in inputs:
print(name, ' is ', age, ' years old')
inputs = [('Abi', 27), ('Abi', 24), ('1', 27), ('Ragu', 26)]
inputs.sort()
# [('1', 27), ('Abi', 24), ('Abi', 27), ('Ragu', 26)]
print(inputs)
# numbers = [23,4,6,6]
# numbers.sort()
# numbers.sort(reverse=True)
# sorted_list=[]
# for i in numbers:
# if(i<=(i+1)):
# test_tuple()
# print(numbers)