Tuple

Run Settings
LanguagePython
Language Version
Run Command
# Tuple my_tuple = (1,2,3,4,5) # methods similar to list! print(my_tuple[1]) print(2 in my_tuple) # Unlike list if we use a tuple we are specifying to not change the values in the tuple! # When other programmer sees a tuple he knows that the values inside it are not going to be changed unlike a list. # A dict can have tuple as a key. user = { (1,2) : [1,2,3] } print(user[(1,2)]) # we can also have a new tuple a copy using indexing new_tuple = my_tuple[1:3] print(new_tuple) # Tuple unpacking x,y,z, *other = (1,2,3,4,5) print(x) print(y) print(z) print(other) # we get a list # A tuple only has 2 methods - count and index! print(my_tuple.count(1)) print(my_tuple.index(1)) print(len(my_tuple))
Editor Settings
Theme
Key bindings
Full width
Lines