what is a tuple in python

Solutions on MaxInterview for what is a tuple in python by the best coders in the world

showing results for - "what is a tuple in python"
Liam
13 Oct 2016
1my_tuple = ("hello")
2print(type(my_tuple))  # <class 'str'>
3
4# Creating a tuple having one element
5my_tuple = ("hello",)
6print(type(my_tuple))  # <class 'tuple'>
7
8# Parentheses is optional
9my_tuple = "hello",
10print(type(my_tuple))  # <class 'tuple'>
Serena
10 Jan 2021
1t = 12345, 54321, 'hello!'
2print(t[0])
3# output 12345
4print(t)
5# output (12345, 54321, 'hello!')
6# Tuples may be nested:
7u = t, (1, 2, 3, 4, 5)
8print(u)
9# output ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))
10# Tuples are immutable:
11# assigning value of 12345 to 88888
12t[0] = 88888
13Traceback (most recent call last):
14  File "<stdin>", line 1, in <module>
15TypeError: 'tuple' object does not support item assignment
16# but they can contain mutable objects:
17v = ([1, 2, 3], [3, 2, 1])
18print(v)
19# output ([1, 2, 3], [3, 2, 1])
Leonardo
18 Mar 2016
1#a tuple is basically the same thing as a
2#list, except that it can not be modified.
3tup = ('a','b','c')
Tommaso
11 Oct 2019
1# There are more ways to create a TUPLE in Python.
2
3# First of all, a TUPLE is usually created by:
4# (STEP 1) creating a Parethesis ()
5# (STEP 2) putting a value in Parenthesis. Example: (3)
6# (STEP 3) putting more value by adding Comma. Example: (3, 4)
7# (STEP 4) Repeat Step 3 if u want to add more value. Example: (3, 4, coffee)
8# That's how to create TUPLE
9
10# EXAMPLE
11adsdfawea = (123, 56.3, 'cheese')
12
13# But did you know, you can create TUPLE without any value inside the () ???
14wallet = ()
15print(type(wallet))
16
17# But did you know, you can create TUPLE without parenthesis () ???
18plate = 'cake',
19print(type(plate))
20
21# As you can see, STRING is possible in TUPLE, not just INTEGERS or FLOATS.
22
23
Victoria
11 Aug 2018
1a=(1,2,3,4)
2print(a[-3])
3
4
Andrea
17 Nov 2016
1example = [1, 2, 3, 4]
2# Here is a list above! As we both know, lists can change in value
3# unlike toples, which are not using [] but () instead and cannot
4# change in value, because their values are static.
5
6# list() converts your tuple into a list.
7tupleexample = ('a', 'b', 'c')
8
9print(list(tupleexample))
10
11>> ['a', 'b', 'c']
12
13# tuple() does the same thing, but converts your list into a tuple instead.
14
15print(example)
16
17>> [1, 2, 3, 4]
18
19print(tuple(example))
20
21>> (1, 2, 3, 4)
queries leading to this page
python reference tuplewhen to use tuples in pythontuple python nedirtuples in pyhtotuple python methodswhat is a python tuplewhat are tuples in pythonpython print tubpleaccess tuple wherehow to use tuples pythonapply tuple pythontuple function pythonadding tuples in pythonuse of tuples in pythonaccess tuples pythonwhat is tuples in pythonmore ways to create tuple pythonhow to create a python tuplepython tupletuple functiondefine tuplestuple in pythonpython tuples basicscommands that work on tuples in pythontuple take pythonpython turplestuple in pyton syntaxpython program to implement tuple function tuple built in functions in pythonhow to create a tuple i pythonpython make tupletuple with for pythonhow to define a tuple in pythonaccessing tuples in pythontuple in python what isnumber in python tupletuple file in pythontuple in function pythoncoding tuple pythontuple access in pythonpython create tuple tuple syntaxhow is tuple implemented in pythontuples in pyhtonpython tuple usagetuple tuple pythontuple command in pythontuple 27 pythonpython tuplapython create use 2a with tuplepython how to access tuplespython to tuplemake a tuple pythontuple methods python 3 python tupletuple in python documentationpython use for tuplespython tuple gettuple in list in pythonpython tuple declarationcreate typple with for pythontuples python simple definitionpython tuples examples tuple python meaningpython tuple 2acreating a tuple in pythontuple typehint in pythonpython touplespython for tupleswhat is a tuple python 3declare a tupletuple 28 29 function pythonprogram in python to print in tuplmethods in tuplein pythonhow to declare a tuple in pythonaccess tuple elements pythontuple in a list pythonhow to tuplets on pythoncreate tuples in pythonpython define a tupletuplein pythonsyntax of a tuplehow to access tuple elementspython tuple exampleaccess tuple in tuple pythonprint a tuplepython reference tuple valueshow to declare a tupledefine tuple pythonpython tuple implementationhow elements in tuple pythonhow do you access info in tuple in pythontuple loop pythonhow to define tuple in pythonpython operations on tuplesin at python tupletuples operationspythonpython example tuplepython in tupletuple inside list pythonexamples of tuples in pythonpython tuple of tuplespython when to use tupletuple example in pythontuples real pythondefinition tuplewhat does tuple 28 29 do in pythontuple library pythonpython tupelwhy do we use tuples in pythonpython how to construct a tupleuntuple tuple pythonhow to write a tuple in pythontupple examplehow to use tuples in pythonhow to code tuplein pythonhow to make tuples pythonbasic tuple operations in pythonmkae tuple of 3 python 28 2c 1 29 tuplepython 2b tuple 2btuple accesshow to create a tuple in pythontuple 2btuple1 in python 2a in python for tuplehow to access tuples pythonpython create tuple from loopingtuple meaning in pythontuple declaration pythonaccessing a python tupletuple method in pythontuples definition in pythontype tuple pythonget in tuple pythonhow to use tuple values in a function in pythonpython tuple of typeswork of tuples in pythonget tuple in pythonpython tuples are 3fdefine tuple in pythonwhat is tuplein pythonel in python tuplehow to give a tuple in pythonhow to read a tuple in pythontuples functions pythondeclare tuple pythonaccess a tuple pythonpython tuplesending tuple pythontuple value pythonhow to do a tuple in a tuple pythonhow do you make a tuple in python 3tuple functions in pythonpython how to make tupleuse of tuple in pythontuple function in pythonways to create tuple in pythontuple list pythonwhats tuple pythonhow many ways to make tuple in pythontuple in list pythonpython tuple 5b0 5d 3d tuple 5b1 5d 2b tuple 5b2 5dhow to output a tuple in pythonhow to create a tuples inpythonaccess tuple in pythonpython tuples methodspython creating tuplestuple in python exampleways to create tuple pythontuple in python docs pythonwhere would we use python tupleget tuple from function pythontuple keyword pythonfor tuple pythonhow to access the tuple in pythonpython tuple valuehow to access a typletuple values pythontuple in python pytypeimport tuple pythonpython tuple classaccessing a tuple in pythontuples methods pythonmake tuple in pythontuple definition pythonwhy is tuple used in pythondictionary python 3explain tuples and various operations on in in python with examplesprint tuple python errorwhat is the use of tuple in pythonpython tuples what is ittuples in python beginnersmeaning of tuple in pythontuple to 7b 7d in pythonpython what is tupletuple of tuples in pythontuple of pythonhow to crate a tuplepython tupletpython declare tuplepython tuplesumpython tuple 29tuples in python3typle in pythonpython tuple importdeclare tuplepython to tupplewhats a tuple in pythonpython tuplespython tuple methodpython tubplespython tuple 28 29what tuple in python istuples function in pythontuple data type in pythonhow to give tuple to function pythonprint from tuplehow to make a tuple in pythonwhy tuple in pythontuple element pythonall tuple methods in pythonlist and tuple in pythontuples in python usagetuple functions pythonwhen do you use tuples in pythonhow to use a tuple in pythontuple variable pythontuple 5bin 2c 5d meaning in python explain tuples in pythontuples python exampletuple functions in python 3tuple declaration in pythontuple formatpython 2atuplepython tuples are tuplespython what is a tuplewhat is the work of tuple in pythoncreate tuple pythontuple get value pythoncreate tuple in pythonpython working with tuplespython how to make tupleswhat is a tuple in python 3how to make a tuplet in pythontupel in pythonpython tuples in listtuple pythonfunctions for tuple in pythontuple python definitiontuple funcs pythondeclare tuple in pythontuples pyhtontuple in python 3functions on tuples in pythontuple operationsaccess a tuple in pythoncan you use for in tuple in pythontuple item 28 29 pythonpython tuple listtuple creation in pythonprint tuple in pythonpython how to use tuplesprint tuple pythontuples in pythonpython tuples exampletuple is pythonhow to query tuples in pythonand operations in python tuplespython tuple 2b tuplecalling tuples in pythontuple to elements pythonwhat does tuple do in pythontuple 2a pythonpython why use tupleswhere tuple is used in pythonpython tuple statements tuple 28 29 pythonhow do you create a tuple in pythonpython call tuplewhat is tuple in python with examplehow to get from tuple pythonhow to make a named tuple in pythontuple python datatupples pythontuple functions in pythontuple nedir pythonoperations on tuples in pythonhow to accept tuple in pythonfunctions on tuple in pythontuple 28x 29tuple 28 29tuple real pythonaccesss tuplesmake a tuple in pythontuple methods pythonpython function tuplehow to create a tuple pythoncalling a tuple in pythontuple en pythonworking with tuples in pythoncreate new tuple python 2a tuple pythonpython tup 3bepython tuple com 28 29what are tuples in python used forpython declare a tuplepython tp tuplewhat is a tuple pythonwhat are python tuplewhat is a tuple in pythontuples list in pythontuple 28x 2c 29 pythonpytnon tuple examplehandling tuples in pythonwhat are python tupleswhat is tuple in pythonaluse to display tuplestuples data type in pythonget a tuple element pythoncreate a tuple pythontuple type in pythonwhat is a tuplesin pythonpython tuple methodstouple pythontime to make a tuple in pythontuple documentation pythonhow to declare a tuple in python 3python is tupletuples in python 3how to declare tuple in pythontup function in pythonhow to use tuple in pythonproperties of tuple in pythontuples pythonwhat is python tuplepython3 tuplehow to access tuple in a tuple pythontuples and list in pythontuple python 5b 5dtuple with tupleshow to access tuples in pythonmethods of tuple in pythonprint tupleaccessing tuples pythontuples functions in pythonwrite a program to demonstrate working with tuples in python tuples operations in pythontuple 28list 29 pythontuples in list pythonuses of tuples in pythontuple operations in pythonall 28 29 tuple pythonwhats a tuple python tuple pythonmake tuples in python why we use tuple in pythontuple in tuple pythontuple 28 29 pythonpython org tuplehow to assign tuple in pythontuple definition in pythontuples with pythonhow to create tuple in pythontuples defhow to access tuple in pythonuntuple a tuple pythonwhat is a python tuple 3f 2atuple pythontuple examplehow to view tupplepython tuple forpython tuple functionspython access tuple of tuplestuple in pythondisplay tuple pythonpython tuping tupletuplees in pythonpython for tupletuples in def pytontuple python 3how to generate tuple in pythonpython tuples listhow to access tuple in pythonwhat is a tuple give an examplehow are tuples made in pythonget a tuple from function pythonfor in tuples 28tuple 29 pythonhow to make a tuple pythonpython numbers in tupleaccess tupletuple 28 29 e2 80 93 does in python 3fexample of a tuplepoython tuplespython set value of tuplecreate a tuple in pythontuple 2b tuple pythonhow to create a tuple in python with variablepython how to create a tuplehow to read tuple in pythontuple elements pythonfor tuple of tuples pythonpython declare a turpletuple functions in python with examplespython 3 tuples with 2cdata tuple pythonpython 2a tuplepython tuple functionpython tuplelsfor on tuple of tuple pythonstore tuple pythonoperation on tuple in pythontuple syntax in pythonpython how to for tupledeclaring a tuple in pythontuple methods in pythonwhat are tuples used for in pythonpython python tuple 2b 3d python tupletuple definitiontuple in pythonhow to access a tuple in pythonfunctions for tuples in pythonhow to call tuple in pythontuple 283 2c 29accessing tuple in pythonhow to use a tuple in a tuple in pythonmake tuple pythonwhen are tuples used in pythoncreate a tuple python 3how to make tuple in pythonaccess item in tuple pythontuple reference pythonwhy would you use tuples in pythonhow to create tuple pythontuples in pytohnto tuple pythontuples methods in pythoncreate tuple from tuple pythonpython use a tuplepython example of a tuplereading tuple in pythonmaking a tuple in pythonwhat is a tuple in python