python tuple vs list

Solutions on MaxInterview for python tuple vs list by the best coders in the world

showing results for - "python tuple vs list"
Elías
24 Jul 2018
1#tuples and lists are the same thing, but a tuple cannot be changed
2tup = (1,'string',True)
3lst = ['hiya',23545,None]
Renata
17 Apr 2017
1mylist : list = [] # <-- a list variable can be defined either as [] or <varname> : list
2mytuple : tuple = () # <-- a tuple variable can be defined either as () or <varname> : tuple
Reuben
15 Oct 2017
1# compare the size
2import sys
3my_list = [0, 1, 2, "hello", True]
4my_tuple = (0, 1, 2, "hello", True)
5print(sys.getsizeof(my_list), "bytes")
6print(sys.getsizeof(my_tuple), "bytes")
7
8# compare the execution time of a list vs. tuple creation statement
9import timeit
10print(timeit.timeit(stmt="[0, 1, 2, 3, 4, 5]", number=1000000))
11print(timeit.timeit(stmt="(0, 1, 2, 3, 4, 5)", number=1000000))
12
queries leading to this page
python when to use list vs tuplewhen to use a list vs tuplepython set vs tuple vs listarray vs list vs tuple in pythonwhy are tuples used in pythonpython set vs list vs tuplelist vs tuple comparisonlist vs tuple typewhat is a tuple vs listtuple vs list in pythonpython tuples vs listspython 28 29 vs listpython declare list vs tuplepython list vs tuplepython why would you use a tuple vs listdifference between list 2c tuple and array in pythontuple in python vs list pythonlist vs tuple vs set pythonpython list vs tuplestuple vs tuple pythonlist vs tuplepython lists vs tupleslist vs tupleslists vs tuples in pythonpython list or tuplepython list vs tuple vs settupple vs list pythonpython 3 list tuple comparisionpython sets vs lists vs tupleslit of tuples instead of tuple of listswhat is a list vs tuple in pythonpython tuple or listpython tuple vs listlist vs tuple syntaxlist vs tuple pythobntuple vs list pythontuple vs list vs distlist in python vs tuplepython tuple vs lstwhy to use tuples instead of listswhat is the difference between a python tuple and python listtuples python vs listtuples vs lists pythonlist vs tuple in python with examplelist of depths pythonpython 3 tuple vs listtuple vs list python espa c3 b1olwhen to use tuple vs list in pythonpython tuples instead of liststuple list differencetuples vs listetuples in python vs listlist vs tuple differencepython str listdifference between list and tuple in pythonlists vs tuples pythonlist vs tuple in pythonlist vs tuple pythonpython lost vs tuplepython tuple vs lsitlist and tupleswhen to use tuples and when to use listslist vs tuple pythhonwhat are tuples used for in pythonpy list vs tuplehat is the difference between a python tuple and python listlists vs tuplespython list tupletuple vs list pytuple python vs listpython listvs tupletuple vs list pyhtontuple versus listpython list versus tuplepython list vs tuple vswhen to use tuple vs listwhen to use a tuple vs a listlist vs tuple difference between tuple and list in pythonlist and tuple in pythonarray vs list vs tuple pythonpython tuple notation versus listtuple or list pythontuples vs listtuple in python vs listwhen do we use tuples in pythonpython tuple vs list vs setpython list vs tuple examplewhat is tuple vs list in pythontuples vs liststupple vs listpython typle vs listtuples vs lists in pythonlist vs tuplset vs list vs tupletuple vs listlist with tuples or not pythonlist vs tuple difference pythontuple versus list pythonpython tuple vs list