Applications

🙋 Need help? Ask an expert now!

Using Tuples in your code!

  1. Length of a Tuple
            
tup = (1,2,3) print(len(tup)) # will return 3!
  1. Concatenation of Tuples
            
tup1 = (1,2,3) tup2 = (3,4,5) print(tup1 + tup2) # Will return (1,2,3,4,5,6)
  1. Repetition
            
tup = ('hello',)*4 print(tup) # Returns ('hello', 'hello', 'hello', 'hello')
  1. Membership
            
print(3 in (1, 2, 3)) #returns True
  1. Iteration:
            
for x in (1, 2, 3): print(x) # prints out 1,2,3

Built in functions:

  • len(tuple) gives the length
  • max(tuple) gives the max value
  • min(tuple) gives the min value
  • tuple(seq) turns a sequence into a tuple