Answers for "python define tuple"

0

py tuple

# Different types of tuples

# Empty tuple
my_tuple = ()
print(my_tuple) # ()

# Tuple having integers
my_tuple = (1, 2, 3)
print(my_tuple) # (1, 2, 3)

# tuple with mixed datatypes
my_tuple = (1, "Hello", 3.4)
print(my_tuple) # (1, 'Hello', 3.4)

# nested tuple
my_tuple = ("mouse", [8, 4, 6], (1, 2, 3))
print(my_tuple) # ('mouse', [8, 4, 6], (1, 2, 3))
Posted by: Guest on January-04-2021
0

tuple python

#tuple
#they are similar to lists but with property of immutable
#and use of parentheses they become variant.
#tuples seperate the objects with notation as commas.
tup=(55,4.00,5,9,9,3.0,9j,3)
print(tup).....................(55,4.00,5,9,9,3.0,9j,3)
tup[3]
print(tup).................9
#functions used here are
count,index
tup.count(9).....................2

tup.index(4.0)....................1
-----------------------------------------------------------------
Posted by: Guest on November-27-2021

Browse Popular Code Answers by Language