FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
2.5k views
in Python Programming by Goeduhub's Expert (3.1k points)
retagged by

This articles deals  with tuple in python that is; What is tuple in Python , Slicing of tuple and  accessing tuple elements etc...

Related Links: Basic Python 

by (100 points)
Tuples are a sequence of python objects and they can't be removed or deleted.

4 Answers

1 like 0 dislike
by Goeduhub's Expert (3.1k points)
edited by
 
Best answer

Tuple

Tuple is a sequence of python objects like list with immutable feature. We cannot add or remove an item in tuple.

tuple is closed by parentheses.

Some examples to understand tuple 

Example (Simple variable declaration and creating tuple)

x,y = 3,4

print (x,y)

a,b,c = 10,11,12

print(a,b,c)

print(b)

tuple=('a','b','c','d','e','f')

print(tuple)

Output

3 4

10 11 12 

11

('a', 'b', 'c', 'd', 'e', 'f')

Example  ( Slicing of tuple )

tup = ('a','e','i','o','u') #Form a tuple with name tup

print("tup is", tup)

print(tup[0])

print(tup[1])

print(tup[-1])

print(tup[-2])

print(tup[1:3])

print(tup[:3])

Output

tup is ('a', 'e', 'i', 'o', 'u') 

('e', 'i') 

('a', 'e', 'i')

 Example (deleting elements in tuple  and tuple itself )

tup[1]='r'

print(tup)

del tup

print(tup)

Output 1 

TypeError Traceback (most recent call last) <ipython-input-24-945701b00000> in <module> ----> 1 tup[1]='r' 2 print(tup) TypeError: 'tuple' object does not support item assignment

Error Reason- Tuple's are immutable this is the reason for error.


NameError Traceback (most recent call last) <ipython-input-26-bcdbccb5f0f8> in <module> 1 del tup ----> 2 print(tup) NameError: name 'tup' is not defined

Error Reason- We deleted tuple already so there is no 'tup' any more.

 Example (Basic Functions on tuple)

 t1=(1,2,3,4)

t2=('a','e','i','o','u') 

T=t1+t2 # add two tuples

print(T)

len(t2) #show length of tuple 

Output

(1, 2, 3, 4, 'a', 'e', 'i', 'o', 'u')
5

Note- Basic tuple functions and methods are same as list.

Python Tutorial 

Machine Learning Tutorial 

AI Tutorial

Free Online Tutorials

by (101 points)
i read it completely
by (422 points)
Tuple is a immutable and it's operations is same as list.
by (294 points)
In this chapter I learned that tuple is list which immutable
by (102 points)
Date:25/04/2020
Topic: TUPLE
Today i learned about tuple it similar to python list but we can not add or delete any element from tuple .learned how to add two tuple and find length.

Thank you
by (100 points)
In this article, i learned about tuples in python. Tuples are immutable and we can perform slicing operations on tuples too.
0 like 0 dislike
by (391 points)
Date: 23/04/2020

Topic: Python tuples

I have learned that tuples are like a list but it cannot be change. We cannot delete, add an item in tuples. How to do slicing of tuples and also learned some errors meaning and why errors occurs.
0 like 0 dislike
by (182 points)

Module:-python tuples      Date:-24/04/2020

In this module i have learnt about tuples.Tuple is a sequence of python objects means like a list.We can't add or remove an item in tuple.And i have learnt also how to declare a tuple and how to use and we can make a tuple of list and slicing of tuple.

Thank you !

0 like 0 dislike
by (294 points)

In this module i have learnt about tuples.Tuple is a sequence of python objects means like a list.We can't add or remove an item in tuple.And i have learnt also how to declare a tuple and how to use and we can make a tuple of list and slicing of tuple.

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

2 like 0 dislike
4 answers 4.0k views
asked Dec 21, 2019 in Python Programming by Nisha Goeduhub's Expert (3.1k points)
0 like 0 dislike
5 answers 2.5k views
2 like 0 dislike
7 answers 10.1k views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...