kothvandir
0
Q:

pyhton tuple

# An empty tuple 
empty_tuple = () 
# Another for doing the same 
tup = ('python', 'geeks') 
# Access first element
print (tup[0]) 
11
#a tuple is basically the same thing as a
#list, except that it can not be modified.
tup = ('a','b','c')
4
#It's like a list, but unchangeable
tup = ("var1","var2","var3")
tup = (1,2,3)
#Error
2
example = [1, 2, 3, 4]
# Here is a list above! As we both know, lists can change in value
# unlike toples, which are not using [] but () instead and cannot
# change in value, because their values are static.

# list() converts your tuple into a list.
tupleexample = ('a', 'b', 'c')

print(list(tupleexample))

>> ['a', 'b', 'c']

# tuple() does the same thing, but converts your list into a tuple instead.

print(example)

>> [1, 2, 3, 4]

print(tuple(example))

>> (1, 2, 3, 4)
0

New to Communities?

Join the community