SlideShare a Scribd company logo
List - Create list
# empty list
my_list = []
# list of integers
my_list = [1, 2, 3]
# list with mixed datatypes
my_list = [1, "Hello", 3.4]
# nested list
my_list = ["mouse", [8, 4, 6], ['a']]
my_list = ['p','r','o','b','e']
print(my_list[0]) # Output: p
print(my_list[2]) # Output: o
print(my_list[4]) # Output: e
print(my_list[-1]) # Output: e
print(my_list[-5]) # Output: p
n_list = ["Happy", [2,0,1,5]]
print(n_list[0][1]) # Output: a
print(n_list[1][3]) # Output: 5
List – Access list element
my_list = ['p','r','o','g','r','a','m','i','z']
# elements 3rd to 5th
print(my_list[2:5])
# elements beginning to 4th
print(my_list[:-5])
# elements 6th to end
print(my_list[5:])
# elements beginning to end
print(my_list[:])
List – Access list element
List – Change or Add elements
# mistake values
odd = [2, 4, 6, 8]
odd[0] = 1 # change the 1st item
print(odd) # Output: [1, 4, 6, 8]
odd[1:4] = [3, 5, 7]
print(odd) # Output: [1, 3, 5, 7]
odd = [1, 3, 5]
odd.append(7)
print(odd)
# Output: [1, 3, 5, 7]
odd.extend([9, 11, 13])
print(odd)
# Output: [1, 3, 5, 7, 9, 11, 13]
List – Delete elements
my_list = ['p','r','o','b','l','e','m’]
del my_list[2] # delete one item
print(my_list) # Output: ['p', 'r', 'b', 'l', 'e', 'm']
del my_list[1:5] # delete multiple items
print(my_list) # Output: ['p', 'm']
del my_list # delete entire list
print(my_list) # Error: List not defined
List Method – append()
• It is used to add elements to the last position of List.
List = ['Mathematics', 'chemistry', 1997, 2000]
List.append(20544)
print(List)
['Mathematics', 'chemistry', 1997, 2000, 20544]
List Method – insert()
List = ['Mathematics', 'chemistry', 1997, 2000]
List.insert(2,10087)
print(List)
• It is used to insert element at specific position.
['Mathematics', 'chemistry’, 10087, 1997, 2000]
List Method – extend()
• Add multiple values or another list into the end of the current list
List1 = [1, 2, 3]
List2 = [2, 3, 4, 5]
# Add List2 to List1
List1.extend(List2)
print(List1)
#Add List1 to List2 now
List2.extend(List1)
print(List2)
[1, 2, 3, 2, 3, 4, 5]
[2, 3, 4, 5, 1, 2, 3, 2, 3, 4, 5]
List Method – sum(), count(), len(), min(), max()
List = [1, 2, 3, 4, 5 , 1]
print(sum(List)) //16
print(List.count(1)) //2
print(len(List)) //6
print(min(List)) //1
print(max(List)) //5
List Method – sort(), reverse()
List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]
#Reverse flag is set True
List.sort(reverse=True)
print(List)
sorted(List)
print(List)
[5.33, 4.445, 3, 2.5, 2.3, 1.054]
[1.054, 2.3, 2.5, 3, 4.445, 5.33]
List Method – pop(), del(), remove()
pop(): Index is not a necessary parameter, if not mentioned takes the last index.
del() : Element to be deleted is mentioned using list name and index.
remove(): Element to be deleted is mentioned using list name and element.
List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]
print(List.pop())
print(List.pop(0))
del List[0]
print(List)
print(List.remove(3))
2.5
2.3
[4.445, 3, 5.33, 1.054, 2.5]
[4.445, 5.33, 1.054, 2.5]

More Related Content

What's hot

Open course(programming languages) 20150121
Open course(programming languages) 20150121Open course(programming languages) 20150121
Open course(programming languages) 20150121
JangChulho
 
Array
ArrayArray
Array
hinanshu
 
Sets
SetsSets
PHP array 1
PHP array 1PHP array 1
PHP array 1
Mudasir Syed
 
Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
monikadeshmane
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology Initiative
Basil Bibi
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
vikram mahendra
 
Tuple.py
Tuple.pyTuple.py
Tuple.py
nuripatidar
 
Python Collection datatypes
Python Collection datatypesPython Collection datatypes
Python Collection datatypes
Adheetha O. V
 
4.1 PHP Arrays
4.1 PHP Arrays4.1 PHP Arrays
4.1 PHP Arrays
Jalpesh Vasa
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arraysmussawir20
 
Arrays in CPP
Arrays in CPPArrays in CPP
Arrays in CPP
Shakila Mahjabin
 
Data structure in perl
Data structure in perlData structure in perl
Data structure in perl
sana mateen
 
Php array
Php arrayPhp array
Php array
Nikul Shah
 
Inside Enumerable
Inside EnumerableInside Enumerable
Inside Enumerable
Mike Bowler
 
How To Write Set Notation
How To Write Set NotationHow To Write Set Notation
How To Write Set Notation
Don Sevcik
 
Lesson 1.1 basic ideas of sets part 3
Lesson 1.1   basic ideas of sets part 3Lesson 1.1   basic ideas of sets part 3
Lesson 1.1 basic ideas of sets part 3
JohnnyBallecer
 
7. tuples, set & dictionary
7. tuples, set & dictionary7. tuples, set & dictionary
7. tuples, set & dictionary
PhD Research Scholar
 
Array in php
Array in phpArray in php
Array in phpilakkiya
 

What's hot (20)

Open course(programming languages) 20150121
Open course(programming languages) 20150121Open course(programming languages) 20150121
Open course(programming languages) 20150121
 
Array
ArrayArray
Array
 
Sets
SetsSets
Sets
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
 
Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
 
Php array
Php arrayPhp array
Php array
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology Initiative
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 
Tuple.py
Tuple.pyTuple.py
Tuple.py
 
Python Collection datatypes
Python Collection datatypesPython Collection datatypes
Python Collection datatypes
 
4.1 PHP Arrays
4.1 PHP Arrays4.1 PHP Arrays
4.1 PHP Arrays
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
Arrays in CPP
Arrays in CPPArrays in CPP
Arrays in CPP
 
Data structure in perl
Data structure in perlData structure in perl
Data structure in perl
 
Php array
Php arrayPhp array
Php array
 
Inside Enumerable
Inside EnumerableInside Enumerable
Inside Enumerable
 
How To Write Set Notation
How To Write Set NotationHow To Write Set Notation
How To Write Set Notation
 
Lesson 1.1 basic ideas of sets part 3
Lesson 1.1   basic ideas of sets part 3Lesson 1.1   basic ideas of sets part 3
Lesson 1.1 basic ideas of sets part 3
 
7. tuples, set & dictionary
7. tuples, set & dictionary7. tuples, set & dictionary
7. tuples, set & dictionary
 
Array in php
Array in phpArray in php
Array in php
 

Similar to Python List

Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
AnitaDevi158873
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Python lists & sets
Python lists & setsPython lists & sets
Python lists & sets
Aswini Dharmaraj
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
deepalishinkar1
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
AshaWankar1
 
List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 
List Data Structure.docx
List Data Structure.docxList Data Structure.docx
List Data Structure.docx
manohar25689
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
list and control statement.pptx
list and control statement.pptxlist and control statement.pptx
list and control statement.pptx
ssuser8f0410
 
Module-2.pptx
Module-2.pptxModule-2.pptx
Module-2.pptx
GaganRaj28
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
Sakith1
 
lists8.pptx of chapter 12 IP Basic Python
lists8.pptx of chapter 12 IP Basic Pythonlists8.pptx of chapter 12 IP Basic Python
lists8.pptx of chapter 12 IP Basic Python
kvpv2023
 
The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202
Mahmoud Samir Fayed
 
List in Python
List in PythonList in Python
List in Python
Sharath Ankrajegowda
 

Similar to Python List (20)

Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Python lists & sets
Python lists & setsPython lists & sets
Python lists & sets
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
 
Unit - 4.ppt
Unit - 4.pptUnit - 4.ppt
Unit - 4.ppt
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
List in Python
List in PythonList in Python
List in Python
 
List Data Structure.docx
List Data Structure.docxList Data Structure.docx
List Data Structure.docx
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
list and control statement.pptx
list and control statement.pptxlist and control statement.pptx
list and control statement.pptx
 
Module-2.pptx
Module-2.pptxModule-2.pptx
Module-2.pptx
 
Python list
Python listPython list
Python list
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
 
lists8.pptx of chapter 12 IP Basic Python
lists8.pptx of chapter 12 IP Basic Pythonlists8.pptx of chapter 12 IP Basic Python
lists8.pptx of chapter 12 IP Basic Python
 
The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210
 
Pytho lists
Pytho listsPytho lists
Pytho lists
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202
 
List in Python
List in PythonList in Python
List in Python
 

More from Soba Arjun

Java interview questions
Java interview questionsJava interview questions
Java interview questions
Soba Arjun
 
Java modifiers
Java modifiersJava modifiers
Java modifiers
Soba Arjun
 
Java variable types
Java variable typesJava variable types
Java variable types
Soba Arjun
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
Soba Arjun
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questions
Soba Arjun
 
C interview questions
C interview questionsC interview questions
C interview questions
Soba Arjun
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
Soba Arjun
 
Php interview questions with answer
Php interview questions with answerPhp interview questions with answer
Php interview questions with answer
Soba Arjun
 
Computer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary MemoryComputer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary Memory
Soba Arjun
 
Birds sanctuaries
Birds sanctuariesBirds sanctuaries
Birds sanctuaries
Soba Arjun
 
Important operating systems
Important operating systemsImportant operating systems
Important operating systems
Soba Arjun
 
Important branches of science
Important branches of scienceImportant branches of science
Important branches of science
Soba Arjun
 
Important file extensions
Important file extensionsImportant file extensions
Important file extensions
Soba Arjun
 
Java Abstraction
Java AbstractionJava Abstraction
Java Abstraction
Soba Arjun
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java Polymorphism
Soba Arjun
 
Java Overriding
Java OverridingJava Overriding
Java Overriding
Soba Arjun
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
Soba Arjun
 
java Exception
java Exceptionjava Exception
java Exception
Soba Arjun
 
Java Methods
Java MethodsJava Methods
Java Methods
Soba Arjun
 
java Inheritance
java Inheritancejava Inheritance
java Inheritance
Soba Arjun
 

More from Soba Arjun (20)

Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java modifiers
Java modifiersJava modifiers
Java modifiers
 
Java variable types
Java variable typesJava variable types
Java variable types
 
Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questions
 
C interview questions
C interview questionsC interview questions
C interview questions
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
 
Php interview questions with answer
Php interview questions with answerPhp interview questions with answer
Php interview questions with answer
 
Computer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary MemoryComputer Memory Types - Primary Memory - Secondary Memory
Computer Memory Types - Primary Memory - Secondary Memory
 
Birds sanctuaries
Birds sanctuariesBirds sanctuaries
Birds sanctuaries
 
Important operating systems
Important operating systemsImportant operating systems
Important operating systems
 
Important branches of science
Important branches of scienceImportant branches of science
Important branches of science
 
Important file extensions
Important file extensionsImportant file extensions
Important file extensions
 
Java Abstraction
Java AbstractionJava Abstraction
Java Abstraction
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java Polymorphism
 
Java Overriding
Java OverridingJava Overriding
Java Overriding
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 
java Exception
java Exceptionjava Exception
java Exception
 
Java Methods
Java MethodsJava Methods
Java Methods
 
java Inheritance
java Inheritancejava Inheritance
java Inheritance
 

Recently uploaded

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

Python List

  • 1.
  • 2. List - Create list # empty list my_list = [] # list of integers my_list = [1, 2, 3] # list with mixed datatypes my_list = [1, "Hello", 3.4] # nested list my_list = ["mouse", [8, 4, 6], ['a']]
  • 3. my_list = ['p','r','o','b','e'] print(my_list[0]) # Output: p print(my_list[2]) # Output: o print(my_list[4]) # Output: e print(my_list[-1]) # Output: e print(my_list[-5]) # Output: p n_list = ["Happy", [2,0,1,5]] print(n_list[0][1]) # Output: a print(n_list[1][3]) # Output: 5 List – Access list element
  • 4. my_list = ['p','r','o','g','r','a','m','i','z'] # elements 3rd to 5th print(my_list[2:5]) # elements beginning to 4th print(my_list[:-5]) # elements 6th to end print(my_list[5:]) # elements beginning to end print(my_list[:]) List – Access list element
  • 5. List – Change or Add elements # mistake values odd = [2, 4, 6, 8] odd[0] = 1 # change the 1st item print(odd) # Output: [1, 4, 6, 8] odd[1:4] = [3, 5, 7] print(odd) # Output: [1, 3, 5, 7] odd = [1, 3, 5] odd.append(7) print(odd) # Output: [1, 3, 5, 7] odd.extend([9, 11, 13]) print(odd) # Output: [1, 3, 5, 7, 9, 11, 13]
  • 6. List – Delete elements my_list = ['p','r','o','b','l','e','m’] del my_list[2] # delete one item print(my_list) # Output: ['p', 'r', 'b', 'l', 'e', 'm'] del my_list[1:5] # delete multiple items print(my_list) # Output: ['p', 'm'] del my_list # delete entire list print(my_list) # Error: List not defined
  • 7. List Method – append() • It is used to add elements to the last position of List. List = ['Mathematics', 'chemistry', 1997, 2000] List.append(20544) print(List) ['Mathematics', 'chemistry', 1997, 2000, 20544]
  • 8. List Method – insert() List = ['Mathematics', 'chemistry', 1997, 2000] List.insert(2,10087) print(List) • It is used to insert element at specific position. ['Mathematics', 'chemistry’, 10087, 1997, 2000]
  • 9. List Method – extend() • Add multiple values or another list into the end of the current list List1 = [1, 2, 3] List2 = [2, 3, 4, 5] # Add List2 to List1 List1.extend(List2) print(List1) #Add List1 to List2 now List2.extend(List1) print(List2) [1, 2, 3, 2, 3, 4, 5] [2, 3, 4, 5, 1, 2, 3, 2, 3, 4, 5]
  • 10. List Method – sum(), count(), len(), min(), max() List = [1, 2, 3, 4, 5 , 1] print(sum(List)) //16 print(List.count(1)) //2 print(len(List)) //6 print(min(List)) //1 print(max(List)) //5
  • 11. List Method – sort(), reverse() List = [2.3, 4.445, 3, 5.33, 1.054, 2.5] #Reverse flag is set True List.sort(reverse=True) print(List) sorted(List) print(List) [5.33, 4.445, 3, 2.5, 2.3, 1.054] [1.054, 2.3, 2.5, 3, 4.445, 5.33]
  • 12. List Method – pop(), del(), remove() pop(): Index is not a necessary parameter, if not mentioned takes the last index. del() : Element to be deleted is mentioned using list name and index. remove(): Element to be deleted is mentioned using list name and element. List = [2.3, 4.445, 3, 5.33, 1.054, 2.5] print(List.pop()) print(List.pop(0)) del List[0] print(List) print(List.remove(3)) 2.5 2.3 [4.445, 3, 5.33, 1.054, 2.5] [4.445, 5.33, 1.054, 2.5]