What is a Tuple in Python and how to use it?

0 votes
Can someone help me in understanding Tuple, I am new to Python and finding it difficult understand Tuple. Please help.
Mar 4, 2019 in Python by Trisha

4 answers to this question.

0 votes

A tuple is created in a similar way as a list but the values are included in ().


tup3 = "a", "b", "c", "d";
tup1 = ();
Access Tuple
tup1 = ('a', 'b', 1, 2);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print "tup1[0]: ", tup1[0];
print "tup2[1:5]: ", tup2[1:5];


tup1[0]: a
tup2[1:5]: [2,3,4,5]
answered Mar 4, 2019 by Priyaj
• 57,530 points
0 votes

  Tuple is a collection of Python objects.it is similar to a list. The difference between the two is that we cannot change the elements of a tuple once it is assigned whereas in a list, elements can be changed.A tuple is created by placing all the items (elements) inside a parentheses (), separated by comma.


# One way of creation

tup = 'rajesh', 'kumar'


  # Another for doing the same

tup = ('rajesh', 'kumar')



   ('rajesh', 'kumar')
   ('rajesh', 'kumar')

answered Apr 12, 2019 by rajesh
• 1,230 points
0 votes
it is a python sequency which stores group of elements or items. tuple are same as list the main difference is they are inmutable.

where as list is mutable.
answered Jul 17, 2019 by mounika reddy
Hey @Mounika, can you explain your answer a bit with some examples?
0 votes

Tuples  are a  Unchanging sequence of values, each one accessible individually, and a tuple is a basic type in Python. You can recognize tuples when they are created because they are surrounded by ‘()’ parentheses . Tuples contain data such as strings and numbers. Open the python shell and perform the following example.

>>> filler = ("string", "filled", "by a", "tuple")
>>> print("A %s %s %s %s" % ("string", "filled", "by a", "tuple")
A string filled by a tuple

>>> print("A %s %s %s %s" % filler)
A string filled by a tuple
answered Jun 21 by sahil
• 500 points

Related Questions In Python

+4 votes
7 answers
0 votes
1 answer

Is there a foreach function in python and is there a way to implement it if there isnt any

Every occurence of "foreach" I've seen (PHP, ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,770 points
0 votes
1 answer

How do I use urllib to see if a website is 404 or 200 in Python?

For Python 3, try doing this: import urllib.request, ...READ MORE

answered Nov 29, 2018 in Python by Nymeria
• 3,540 points

edited Dec 11, 2018 by Nymeria 4,490 views
0 votes
1 answer

What is absolute import in Python and how is it used?

An absolute {import, path, URL} tells you exactly how ...READ MORE

answered Nov 30, 2018 in Python by Nymeria
• 3,540 points

edited Dec 10, 2018 by Nymeria 168 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,052 views
0 votes
0 answers
+1 vote
1 answer

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

answered Aug 20, 2018 in Python by Priyaj
• 57,530 points
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 57,530 points