list vs tuple python

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

showing results for - "list vs tuple python"
Andrés
08 Apr 2018
1#tuples and lists are the same thing, but a tuple cannot be changed
2tup = (1,'string',True)
3lst = ['hiya',23545,None]
María Camila
13 Feb 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
Lia
03 Jun 2020
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
difference between list and tuple in pythonlist vs tupllists vs tuples in pythonpython lost vs tuplelit of tuples instead of tuple of liststuples vs listlist vs tuple comparisonlist vs tuple difference pythonwhy are tuples used in pythonpython why would you use a tuple vs listlist vs tuple in python with examplepython tuple or listlist and tupleslist vs tuple vs set pythonwhy to use tuples instead of listswhen to use a list vs tuplelist vs tuple pythhonpython declare list vs tuplepython str listtuple vs list python espa c3 b1oldifference between tuple and list in pythonlist and tuple in pythonwhat is a list vs tuple in pythontuples vs lists in pythonwhen to use tuple vs listwhen to use a tuple vs a listlist with tuples or not pythonwhat is the difference between a python tuple and python listlist in python vs tuplewhat is a tuple vs listarray vs list vs tuple in pythonpython tuple notation versus listtuple list differencetuple vs list pythonpython list or tupletuple vs list pyhtonpython tuple vs listwhat is tuple vs list in pythonset vs list vs tuplelist vs tuple list of depths pythonpython typle vs listlist vs tuple in pythonpython list vs tuple exampletuple vs listtupple vs list pythonpython 3 list tuple comparisionlists vs tuples pythontuple or list pythonpython list tuplepython lists vs tuplespython listvs tupletuples vs listetuples vs listspython list vs tuplestuples in python vs listtuple vs tuple pythonlist vs tuple syntaxtuple versus list pythonpython tuples vs listslist vs tuple pythonpython sets vs lists vs tuplespython tuple vs list vs settuples python vs listtuple vs list in pythonlist vs tuplepython tuple vs lstarray vs list vs tuple pythondifference between list 2c tuple and array in pythontuple versus listlists vs tuplespython set vs list vs tuplewhat are tuples used for in pythonlist vs tuple pythobnpython list vs tuple vs setlist vs tuple differencepython list vs tuple vstuples vs lists pythonpython 3 tuple vs listpy list vs tuplepython set vs tuple vs listhat is the difference between a python tuple and python listpython tuples instead of liststuple vs list vs distwhen to use tuples and when to use liststuple in python vs list pythonpython list vs tupletupple vs listpython list versus tupletuple vs list pylist vs tupleswhen do we use tuples in pythontuple in python vs listtuple python vs listpython when to use list vs tuplewhen to use tuple vs list in pythonpython tuple vs lsitlist vs tuple typepython 28 29 vs listlist vs tuple python