Course Content

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

Course Content

Description

Tuples in Python

 

In this structure we will see that how to implement tuple with all its operations.

 

Tuple function

 

dir(nameoftuple)

help(nameoftuple.functionname)

 

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

print(tup1)

Output :

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

 

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

tup2=(1)

print(tup1)

print(tup2)

Output :

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

1

 

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

tup2=(1,)

print(tup1)

print(tup2)

Output :

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

(1,)

 

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

print(tup1)

print ("tup1[2]:",tup1[2])

print ("tup1[-3]:",tup1[-3])

print ("tup1[2:5]:",tup1[2:5])

print ("tup1[3:]:",tup1[3:])

print ("tup1[:4]:",tup1[:4])

Output :

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

tup1[2]:3

tup1[-3]:4

tup1[2:5]:(3,4,5)

tup1[3:]:(4,5,6)

tup1[:4]:(1,2,3,4)

 

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

print(tup1)

print ("tup1[2]:",tup1[2])

print ("tup1[-3]:",tup1[-3])

print ("tup1[2:5]:",tup1[2:5])

print ("tup1[3:]:",tup1[3:])

print ("tup1[:4]:",tup1[:4])

print (tup1*2)

print (3 in tup1)

print (len(tup1))

Output :

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

tup1[2]:3

tup1[-3]:4

tup1[2:5]:(3,4,5)

tup1[3:]:(4,5,6)

tup1[:4]:(1,2,3,4)

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

True

6

 

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

for element in tup1:

print(element)

Output :

1

2

3

4

5

6

 

To check how many functions do tuple have :

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

print(dir(tup1))

 

To check the index of element in tuple :

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

print (tup1.index(4))

Output :

3

 

To count particular element in tuple :

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

print (tup1.count(2))

Output :

3

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