0% found this document useful (0 votes)
0 views3 pages

Python Programming 5

Uploaded by

shraddhavinod1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views3 pages

Python Programming 5

Uploaded by

shraddhavinod1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Tuples-:

# list and tuples are same bt diif. is list is mutable and

# tuples is immutable same as string. use ().

tuples=(1,4,7,3,6,8,5)

print(tuples) #output (1, 4, 7, 3, 6, 8, 5)

print(type(tuples)) #output <class 'tuple'>

#indexing

print(tuples[0]) #output 1

print(tuples[3]) #output 3

print(tuples[4]) #output 6

print(tuples[6]) #output 5

#can not assign value

# tuples[1]=15 #output error

#empty value

tuple=()

print(tuple) #output ()

print(type(tuple)) #output <class 'tuple'>

#Single value

tuple=(4,)

print(tuple) #output (4,)

print(type(tuple)) #output <class 'tuple'>

#Single value without comma ,

tuple=(4)

print(tuple) #output (4)

print(type(tuple)) #output <class 'int'>


#tuple slicing same as string

# tuple[starting_idx : ending_idx] ending index is not included

tuple=(3,5,8,2,9,10)

print(tuple[2:4]) #output (8, 2)

print(tuple[1:5]) #output (5, 8, 2, 9)

print(tuple[2:3]) #output (8,)

#tuples methods

# 1) tuple.index(el) return index

tuple=(4,7,2,6,9,4,6,2,2)

print(tuple.index(6)) #output 3

print(tuple.index(2)) #output 2

# 2)tuple.count(el) return count

tuple=(4,7,2,6,9,4,6,2,2)

print(tuple.count(6)) #output 2

print(tuple.count(2)) #output 3

# write a program to print three movies and store them in a list

movies=[]

mov1=(input("Enter the 1st movie names"))

mov2=(input("Enter the 2nd movie names"))

mov3=(input("Enter the 3rd movie names"))

movies.append(mov1)

movies.append(mov2)

movies.append(mov3)

print(movies)

You might also like