Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Tuples in Python

 

In this video we will see that,

What is tuple ?

Which are the different operations of tuple ?

Which functions are available for tuple ?

 

A tuple is a sequence of immutable python objects. Tuples are sequences, just like lists. They cannot be changed, once defined.

 

The differences between tuples and lists are, the tuples cannot be changed unlike lists are tuples use parentheses, whereas lists use square brackets.

 

Example of Tuple :

tup1=(1,2,3,4,5);

tup2="a","b","c","d";

tup3=('python','java',25.45,1997,2000);

 

Accessing values in tuple

 

tup1=(1,2,3,4,5)

 

print(tup1[0])

print(tup2[1:5])

 

Updating tuple

 

Tuples are immutable which means you cannot update or change the values of tuple elements.

 

tup3=tup1+tup2

print tup3

 

Delete tuple

 

Remove in individual tuple elements is not possible.

 

Tuple Operation

 

Python Expression

Results

Description

len((1,2,3))

3

Length

(1,2,3) + (4,5,6)

(1,2,3,4,5,6)

Concatenation

(‘hi’)*4

(‘hi’,’hi’,’hi’,’hi’)

Repetition

3 in (1,2,3)

True

Membership

for x in (1,2,3) :

print x,

1 2 3

Iteration

 

Tuple indexing, slicing, and matrixes

 

T=(1,2,3,4,5,6)

 

Python Expression

Results

Description

T[2]

3

Offsets start at zero

T[-2]

5

Negative: count from the right

T[1:]

(2,3,4,5,6)

Slicing fetches sections

 

 

 

 

 

FAQs

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere