SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Lists
List can store a sequence of values belonging to any datatype.
'Hi' 3 2.6 ‘S’ ‘Two’
L = [‘Hi’, 3, 2.6, ‘S’, ‘Two’] or L = list(<sequence>)
L :
Playing with Lists
■ Creating Lists
L = list(‘LockDown’)
print(L) [‘L’, ‘o’, ‘c’, ‘k’, ‘D’, ‘o’, ‘w’, ‘n’]
L = list( input(‘Enter elements : '))
print(L)
Takes one string, make each character as one element in List.
Playing with Lists
■ Lists vs Strings
Similarities :
Len( ), Indexing & Slicing, Membership, Concatenation & Replication
Differences :
Storage : Strings store single character at each block, Lists store references.
Mutability : Strings-Immutable Lists-Mutable
Playing with Lists
■ Appending Elements
L=[2,5,17]
L[3]=12 or L.append(12)
■ Updating Elements
L[1]=7
■ Deleting Elements
del L[2] deletes element at index 2.
del L[1:4] deletes slice of 1:4 i.e. 1,2 & 3 indices.
del L deletes the whole list.
■ Extending Elements
L = [2,5,17]
L.extend( (21, ‘hi’, [3,6,7]) )
Playing with Lists (other operations are same as strings)
■ Making a True Copy
Colors = [‘red’, ‘blue’, ‘green’]
L2 = Colors ❌
L2 = list(Colors) ✔
In first case, any changes in Colors will reflect in L2 as they both are
referencing the same list.
Lists Functions
Python also offers many built in functions for Lists.
● The index method gives the index of the <element>
L.index(<element>) exception error if not found.
● The extend method
L.extend(<list>) appends <sequence> into L.
append( ) & extend( ) discussed before
Lists Functions
● The insert method
L.insert(<pos>,<item>) inserts <item> at <pos>th
index.
● The pop method
L.pop(<index>) deletes & returns element at <index>.
L.pop( ) deletes & returns last element.
Lists Functions
● The remove method
L.remove(<value>) removes the first occurence of <value>.
● The clear method
L.clear( ) clears the whole list,
[ ], this remains.
● The count method
L.count( <item>) counts the <item> & returns
Lists Functions
● The reverse method
L.reverse( ) reverses the whole list.
● The sort method
L.sort( ) sorts the list in ascending order.
L.sort(reverse = True) sorts the list in descending order.
Practice Time
Q1. List=[1,2,3,4,5,6,7,8,9]
print(List[ : : 3])
Q2. What will be the output of the following code snippet?
a. A = [ ]
for i in range(1,4) :
A.append(i)
print(values)
b. b=[ 1,2,3,4,5 ]
print( b[3:0:-1] )
Tuples
Tuples are basically immutable Lists.
Lists are made by square brackets [ ].
Tuples are made by curved brackets ( ).
t=(1, 'hello', 3.2, ‘w’)
t=tuple('Harsh')
Tuples vs Lists
Following things are same as before :-
● Creating
● Creating using input
● Indexing & Slicing
● Membership
● Concatenation & Replication
● Traversing
T = (1, 2, ‘A’, ‘B’)
w, x, y, z = T variables on the left side must match
the number of elements in tuple.
print(w,x,y,z,sep=’*’)
OUTPUT : 1*2*A*B
Unpacking a Tuple
Tuple Functions
● The len method (same for string & List too)
len(<tuple>) returns length of the tuple.
● The max/min methods
max(<tuple>) returns max element in the<tuple>.
min(<tuple>) returns min element in the<tuple>.
● The index method returns index number of <item>.
t.index(<item>) exception error if not found.
● The count method
t.count(<item>) returns the count of <item> in the tuple.
● The tuple method used to create tuples.
t=tuple('abc') (‘a’, ‘b’, ‘c’)
t=tuple([1,2,3]) tuple from list
t=tuple( ) empty tuple
Tuple Functions
Practice Time
Q1. t = ‘a’ , ‘b’
t2= (‘a’, ‘b’)
print(t==t2)
Q2. What is the length of this tuple?
t=( ( ( (‘a’,1 ), ‘b’, ‘c’ ), ‘d’, 2 ), ‘e’, 3 )
Q3. A= ( ‘Hello’, ‘Harsh’ , ‘How’re’, ‘you ?’ )
( a,b,c,d ) = A
print( a, b, c, d )
A = ( a, b, c, d )
print( A[0][0]+A[1][1], A[1] )

Weitere ähnliche Inhalte

Ähnlich wie Lecture-5.pdf

List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptxChandanVatsa2
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfMCCMOTOR
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdfAshaWankar1
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdfNehaSpillai1
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdfNehaSpillai1
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionarynitamhaske
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonchanna basava
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdfMariappanR3
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptxYagna15
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear listsToniyaP1
 
Module 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxModule 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxGaneshRaghu4
 
Python Collections
Python CollectionsPython Collections
Python Collectionssachingarg0
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfomprakashmeena48
 

Ähnlich wie Lecture-5.pdf (20)

List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptx
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
 
Python ds
Python dsPython ds
Python ds
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
 
Python lists
Python listsPython lists
Python lists
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
Sixth session
Sixth sessionSixth session
Sixth session
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdf
 
Pytho lists
Pytho listsPytho lists
Pytho lists
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptx
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
 
Module 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxModule 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptx
 
Python Collections
Python CollectionsPython Collections
Python Collections
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdf
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Trusted Cricket Betting ID Provider In India: Get your Cricket ID Now
Trusted Cricket Betting ID Provider In India: Get your Cricket ID NowTrusted Cricket Betting ID Provider In India: Get your Cricket ID Now
Trusted Cricket Betting ID Provider In India: Get your Cricket ID Nowbacklinks165
 
Unveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartUnveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartChart Kalyan
 
Hire 💕 8617370543 Amethi Call Girls Service Call Girls Agency
Hire 💕 8617370543 Amethi Call Girls Service Call Girls AgencyHire 💕 8617370543 Amethi Call Girls Service Call Girls Agency
Hire 💕 8617370543 Amethi Call Girls Service Call Girls AgencyNitya salvi
 
Luka Modric Elevating Croatia's Stars for Euro Cup 2024.docx
Luka Modric Elevating Croatia's Stars for Euro Cup 2024.docxLuka Modric Elevating Croatia's Stars for Euro Cup 2024.docx
Luka Modric Elevating Croatia's Stars for Euro Cup 2024.docxEuro Cup 2024 Tickets
 
Spain to be banned from participating in Euro 2024.docx
Spain to be banned from participating in Euro 2024.docxSpain to be banned from participating in Euro 2024.docx
Spain to be banned from participating in Euro 2024.docxEuro Cup 2024 Tickets
 
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...World Wide Tickets And Hospitality
 
UEFA Euro 2024 Clash and Eurovision 2024 Poll Insights.docx
UEFA Euro 2024 Clash and Eurovision 2024 Poll Insights.docxUEFA Euro 2024 Clash and Eurovision 2024 Poll Insights.docx
UEFA Euro 2024 Clash and Eurovision 2024 Poll Insights.docxEuro Cup 2024 Tickets
 
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docxAlbania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docxWorld Wide Tickets And Hospitality
 
Personal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley DennisPersonal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley Dennisjocksofalltradespodc
 
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxNetherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxEuro Cup 2024 Tickets
 
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfJORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfArturo Pacheco Alvarez
 
Italy Vs Albania Italy vs Albania Euro 2024 Prediction Can Albania pull off a...
Italy Vs Albania Italy vs Albania Euro 2024 Prediction Can Albania pull off a...Italy Vs Albania Italy vs Albania Euro 2024 Prediction Can Albania pull off a...
Italy Vs Albania Italy vs Albania Euro 2024 Prediction Can Albania pull off a...World Wide Tickets And Hospitality
 
Cricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdfLatiyalinfotech
 
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdf
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdfCroatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdf
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdfEticketing.co
 
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call GirlsGenuine 8617370543 Hot and Beautiful 💕 Etah Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call GirlsNitya salvi
 
Churu Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Churu Escorts 🥰 8617370543 Call Girls Offer VIP Hot GirlsChuru Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Churu Escorts 🥰 8617370543 Call Girls Offer VIP Hot GirlsDeepika Singh
 
basketball evolution History Slides.pdf
basketball evolution  History Slides.pdfbasketball evolution  History Slides.pdf
basketball evolution History Slides.pdftishvidphotography
 

Kürzlich hochgeladen (19)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Trusted Cricket Betting ID Provider In India: Get your Cricket ID Now
Trusted Cricket Betting ID Provider In India: Get your Cricket ID NowTrusted Cricket Betting ID Provider In India: Get your Cricket ID Now
Trusted Cricket Betting ID Provider In India: Get your Cricket ID Now
 
Unveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar ChartUnveiling the Mystery of Main Bazar Chart
Unveiling the Mystery of Main Bazar Chart
 
Hire 💕 8617370543 Amethi Call Girls Service Call Girls Agency
Hire 💕 8617370543 Amethi Call Girls Service Call Girls AgencyHire 💕 8617370543 Amethi Call Girls Service Call Girls Agency
Hire 💕 8617370543 Amethi Call Girls Service Call Girls Agency
 
Luka Modric Elevating Croatia's Stars for Euro Cup 2024.docx
Luka Modric Elevating Croatia's Stars for Euro Cup 2024.docxLuka Modric Elevating Croatia's Stars for Euro Cup 2024.docx
Luka Modric Elevating Croatia's Stars for Euro Cup 2024.docx
 
Spain to be banned from participating in Euro 2024.docx
Spain to be banned from participating in Euro 2024.docxSpain to be banned from participating in Euro 2024.docx
Spain to be banned from participating in Euro 2024.docx
 
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...
Belgium Vs Slovakia Belgium at Euro 2024 Teams in group, fixtures, schedule, ...
 
UEFA Euro 2024 Clash and Eurovision 2024 Poll Insights.docx
UEFA Euro 2024 Clash and Eurovision 2024 Poll Insights.docxUEFA Euro 2024 Clash and Eurovision 2024 Poll Insights.docx
UEFA Euro 2024 Clash and Eurovision 2024 Poll Insights.docx
 
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docxAlbania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
Albania Vs Spain South American coaches lead Albania to Euro 2024 spot.docx
 
Personal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley DennisPersonal Brand Exploration - By Bradley Dennis
Personal Brand Exploration - By Bradley Dennis
 
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docxNetherlands Players expected to miss UEFA Euro 2024 due to injury.docx
Netherlands Players expected to miss UEFA Euro 2024 due to injury.docx
 
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdfJORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
JORNADA 6 LIGA MURO 2024TUXTEPECOAXACA.pdf
 
Italy Vs Albania Italy vs Albania Euro 2024 Prediction Can Albania pull off a...
Italy Vs Albania Italy vs Albania Euro 2024 Prediction Can Albania pull off a...Italy Vs Albania Italy vs Albania Euro 2024 Prediction Can Albania pull off a...
Italy Vs Albania Italy vs Albania Euro 2024 Prediction Can Albania pull off a...
 
Cricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdfCricket Api Solution.pdf
Cricket Api Solution.pdfCricket Api Solution.pdf
 
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdf
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdfCroatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdf
Croatia vs Italy Inter Milan Looking to Carry On Success at Euro 2024.pdf
 
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call GirlsGenuine 8617370543 Hot and Beautiful 💕 Etah Escorts call Girls
Genuine 8617370543 Hot and Beautiful 💕 Etah Escorts call Girls
 
Slovenia Vs Serbia Eurovision odds Slovenia have top.docx
Slovenia Vs Serbia Eurovision odds Slovenia have top.docxSlovenia Vs Serbia Eurovision odds Slovenia have top.docx
Slovenia Vs Serbia Eurovision odds Slovenia have top.docx
 
Churu Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Churu Escorts 🥰 8617370543 Call Girls Offer VIP Hot GirlsChuru Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Churu Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
 
basketball evolution History Slides.pdf
basketball evolution  History Slides.pdfbasketball evolution  History Slides.pdf
basketball evolution History Slides.pdf
 

Lecture-5.pdf

  • 1. Lists List can store a sequence of values belonging to any datatype. 'Hi' 3 2.6 ‘S’ ‘Two’ L = [‘Hi’, 3, 2.6, ‘S’, ‘Two’] or L = list(<sequence>) L :
  • 2. Playing with Lists ■ Creating Lists L = list(‘LockDown’) print(L) [‘L’, ‘o’, ‘c’, ‘k’, ‘D’, ‘o’, ‘w’, ‘n’] L = list( input(‘Enter elements : ')) print(L) Takes one string, make each character as one element in List.
  • 3. Playing with Lists ■ Lists vs Strings Similarities : Len( ), Indexing & Slicing, Membership, Concatenation & Replication Differences : Storage : Strings store single character at each block, Lists store references. Mutability : Strings-Immutable Lists-Mutable
  • 4. Playing with Lists ■ Appending Elements L=[2,5,17] L[3]=12 or L.append(12) ■ Updating Elements L[1]=7 ■ Deleting Elements del L[2] deletes element at index 2. del L[1:4] deletes slice of 1:4 i.e. 1,2 & 3 indices. del L deletes the whole list. ■ Extending Elements L = [2,5,17] L.extend( (21, ‘hi’, [3,6,7]) )
  • 5. Playing with Lists (other operations are same as strings) ■ Making a True Copy Colors = [‘red’, ‘blue’, ‘green’] L2 = Colors ❌ L2 = list(Colors) ✔ In first case, any changes in Colors will reflect in L2 as they both are referencing the same list.
  • 6. Lists Functions Python also offers many built in functions for Lists. ● The index method gives the index of the <element> L.index(<element>) exception error if not found. ● The extend method L.extend(<list>) appends <sequence> into L. append( ) & extend( ) discussed before
  • 7. Lists Functions ● The insert method L.insert(<pos>,<item>) inserts <item> at <pos>th index. ● The pop method L.pop(<index>) deletes & returns element at <index>. L.pop( ) deletes & returns last element.
  • 8. Lists Functions ● The remove method L.remove(<value>) removes the first occurence of <value>. ● The clear method L.clear( ) clears the whole list, [ ], this remains. ● The count method L.count( <item>) counts the <item> & returns
  • 9. Lists Functions ● The reverse method L.reverse( ) reverses the whole list. ● The sort method L.sort( ) sorts the list in ascending order. L.sort(reverse = True) sorts the list in descending order.
  • 10. Practice Time Q1. List=[1,2,3,4,5,6,7,8,9] print(List[ : : 3]) Q2. What will be the output of the following code snippet? a. A = [ ] for i in range(1,4) : A.append(i) print(values) b. b=[ 1,2,3,4,5 ] print( b[3:0:-1] )
  • 11. Tuples Tuples are basically immutable Lists. Lists are made by square brackets [ ]. Tuples are made by curved brackets ( ). t=(1, 'hello', 3.2, ‘w’) t=tuple('Harsh')
  • 12. Tuples vs Lists Following things are same as before :- ● Creating ● Creating using input ● Indexing & Slicing ● Membership ● Concatenation & Replication ● Traversing
  • 13. T = (1, 2, ‘A’, ‘B’) w, x, y, z = T variables on the left side must match the number of elements in tuple. print(w,x,y,z,sep=’*’) OUTPUT : 1*2*A*B Unpacking a Tuple
  • 14. Tuple Functions ● The len method (same for string & List too) len(<tuple>) returns length of the tuple. ● The max/min methods max(<tuple>) returns max element in the<tuple>. min(<tuple>) returns min element in the<tuple>.
  • 15. ● The index method returns index number of <item>. t.index(<item>) exception error if not found. ● The count method t.count(<item>) returns the count of <item> in the tuple. ● The tuple method used to create tuples. t=tuple('abc') (‘a’, ‘b’, ‘c’) t=tuple([1,2,3]) tuple from list t=tuple( ) empty tuple Tuple Functions
  • 16. Practice Time Q1. t = ‘a’ , ‘b’ t2= (‘a’, ‘b’) print(t==t2) Q2. What is the length of this tuple? t=( ( ( (‘a’,1 ), ‘b’, ‘c’ ), ‘d’, 2 ), ‘e’, 3 ) Q3. A= ( ‘Hello’, ‘Harsh’ , ‘How’re’, ‘you ?’ ) ( a,b,c,d ) = A print( a, b, c, d ) A = ( a, b, c, d ) print( A[0][0]+A[1][1], A[1] )