SlideShare a Scribd company logo
1 of 21
An Introduction To Software
Development Using Python
Spring Semester, 2015
Class #9:
Lists, Part 1
Python Is All About Lists
• What lists do you use in your life today?
• Polytech Florida Common Prerequisites list of
classes: Course ID, Course Name, Course Credits
CHM 2045,Chemistry 1,3
CHM 2045L,Chemistry 1 Laboratory,1
COP 2271c,Introduction to Computation and Programming,3
EEL 3111c,Circuits 1,4
EEL 3112c,Circuits 2,3
MAC 2311,Analytic Geometry and Calculus 1,4
MAC 2312,Analytic Geometry and Calculus 2,4
MAC 2313,Analytic Geometry and Calculus 3,4
MAP 2302,Differential Equations,3
PHY 2048,Physics 1,3
PHY 2048L,Physics 1 Laboratory,1
PHY 2049,Physics 2,3
PHY 2049L,Physics 2 Laboratory,1
Image Credit: Clipart Panda
4 Steps To Creating A Python List
1. Convert each of the names into strings by surrounding the
data with quotes.
2. Separate each of the list items from the next with a comma.
3. Surround the list of items with opening and closing square
brackets.
4. Assign the list to an identifier (movies in the preceding code)
using the assignment operator (=).
“COP 2271c” “Introduction to Computation and Programming” 3
“COP 2271c”, “Introduction to Computation and Programming”, 3
[“COP 2271c”, “Introduction to Computation and Programming”, 3]
prerequisites = [“COP 2271c”, “Introduction to Computation and Programming”, 3]
COP 2271c Introduction to Computation and Programming 3
Image Credit: Clipart Panda1
Python Is Different From Other
Programing Languages!
• Other languages (C, C++, Java, etc.) insist that every identifier used in code
has type information declared for it. Not so with Python: identifiers are
simply names that refer to a data object of some type.
char example1;
int example2 = 5;
void example3(void)
• One way to think of Python’s list is as a high-level collection.
• The type of the data items is not important to the list. All Python needs to
know is that you need a list, you’ve given it a name, and the list has some
data items in it.
Image Credit: Clipart Panda
What Does Your List Look Like
Inside Of The Computer?
COP 2271c
Introduction to Computation and Programming
3
0
1
2
Python
Starts
Counting
At 0
Each item in a list
has an index
number associated
with it…
prerequisites = [“COP 2271c”, “Introduction to Computation and Programming”, 3]
The computer stores
your list data in what is
called an “array”.
How To Access A List
• A list is a sequence of elements, each of which has an
integer position or index.
• To access a list element, you specify which index you
want to use.
• That is done with the subscript operator ([] ) in the
same way that you access individual characters in a
string.
• For example:
print(values[5]) # Prints the element at index 5
Image Credit: imgkid.com
Access Your List Data Using The
Square Bracket Notation
print (prerequisites[0]) COP 2271c
print (prerequisites[1]) Introduction to Computation and Programming
print (prerequisites[2]) 3
Image Credit: Clipart Panda2
You Can Create
Multidimensional Lists
• Lists can hold data of mixed type.
• But it gets even better than that: lists can hold
collections of anything, including other lists.
• Simply embed the inner list within the
enclosing list as needed.
multiDim = [[123],[456],[789]] =
1 2 3
4 5 6
7 8 9
Image Credit: www.rafainspirationhomedecor.com3
Programming Challenge
• How many credits need to be taken to satisfy
Poly prereqs?
Image Credit: www.clker.com4
Did You Know?:
Accessing A List Backwards
• Python, unlike many other languages, also
allows you to use negative subscripts when
accessing an element of a list.
• The negative subscripts provide access to the
list elements in reverse order.
• For example, a subscript of –1 provides
access to the last element in the list:
last = values[-1]
print("The last element in the list is", last)
Image Credit: lessonpix.com
What Is The Difference Between A
List And A String?
• Both lists and strings are sequences, and the [] operator can
be used to access an element in any sequence.
• There are two differences between lists and strings.
– Lists can hold values of any type, whereas strings are sequences of
characters.
– Moreover, strings are immutable—you cannot change the characters
in the sequence. But lists are mutable. You can replace one list
element with another, like this:
values[5] = 87
Image Credit: www.dreamstime.com
What Happens When You
Copy A List?
Image Credit: imgkid.com
Lists Are Much More Than Just
Simple Arrays
• Lists in Python are full-blown Python
collection objects.
• This means that lists come with ready-to-use
functionality in the form of list methods.
BIF
len
Methods
1. append
2. pop
3. remove
4. insert
5. extend
Image Credit: besttoddlertoys.eu
Playing With Lists: Append
• Add teacher: Dr. Jim Anderson
• Add year: 2015
Note: Python lists can contain data of mixed types. You can mix strings with
numbers within the same Python list. You can mix more than just strings and
numbers -- you can store data of any type in a single list.
prerequisites = [“COP 2271c”, “Introduction to Computation and Programming”, 3]
Image Credit: ClipArt Best5
Playing With Lists: Pop
• Allows you to remove the item that is at the
end of a list
prereqs[course].pop()
CHM 2045 , Chemistry 1 , 3 , Dr. Anderson , 2015
X
Image Credit: blog.poolproducts.com6
Playing With Lists: Remove
• Allows you to specify which list item you want
to remove no matter where in the list it is
located
prereqs[course].remove("Dr. Anderson")
CHM 2045 , Chemistry 1 , 3 , Dr. AndersonX
Image Credit: www.pinterest.com7
Playing With Lists: Insert
• Allows you to add an item to a list in a
specified location on the list
prereqs[course].insert(2,"Really Hard")
CHM 2045 , Chemistry 1 , Really Hard , 3
Image Credit: ekskavatör8
Playing With Lists: Extend
• Allows multiple list items to be added to an
existing list
prereqs[course].extend(["Dr. Anderson", "2015"])
CHM 2045 , Chemistry 1 , Really Hard , 3 , Dr. Anderson , 2015
Image Credit: www.clipartpanda.com9
What’s In Your Python Toolbox?
print() math strings I/O IF/Else elif While For
Lists
What We Covered Today
1. Lists
2. Multidimensional lists
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
What We’ll Be Covering Next Time
1. Lists, Part 2
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

More Related Content

What's hot

Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structure
eShikshak
 

What's hot (20)

R Basics and Best Practices
R Basics and Best PracticesR Basics and Best Practices
R Basics and Best Practices
 
Lists methods
Lists methodsLists methods
Lists methods
 
Lists and loops
Lists and loopsLists and loops
Lists and loops
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Coding and Cookies: R basics
Coding and Cookies: R basicsCoding and Cookies: R basics
Coding and Cookies: R basics
 
The List Data Model
The List Data ModelThe List Data Model
The List Data Model
 
Data Structure
Data StructureData Structure
Data Structure
 
Data structure
Data structureData structure
Data structure
 
Dictionaries
DictionariesDictionaries
Dictionaries
 
Introduction to lists
Introduction to listsIntroduction to lists
Introduction to lists
 
Chap10
Chap10Chap10
Chap10
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Binary Search
Binary SearchBinary Search
Binary Search
 
.net F# mutable dictionay
.net F# mutable dictionay.net F# mutable dictionay
.net F# mutable dictionay
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structure
 
C programming
C programmingC programming
C programming
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
 
Data structure & algorithms introduction
Data structure & algorithms introductionData structure & algorithms introduction
Data structure & algorithms introduction
 
Algorithms Intro Lecture
Algorithms Intro LectureAlgorithms Intro Lecture
Algorithms Intro Lecture
 

Viewers also liked

Viewers also liked (15)

An Introduction To Software Development - Architecture & Detailed Design
An Introduction To Software Development - Architecture & Detailed DesignAn Introduction To Software Development - Architecture & Detailed Design
An Introduction To Software Development - Architecture & Detailed Design
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewAn Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm Review
 
An Introduction To Python - Python, Print()
An Introduction To Python - Python, Print()An Introduction To Python - Python, Print()
An Introduction To Python - Python, Print()
 
An Introduction To Python - Nested Branches, Multiple Alternatives
An Introduction To Python - Nested Branches, Multiple AlternativesAn Introduction To Python - Nested Branches, Multiple Alternatives
An Introduction To Python - Nested Branches, Multiple Alternatives
 
An Introduction To Python - WHILE Loop
An Introduction To  Python - WHILE LoopAn Introduction To  Python - WHILE Loop
An Introduction To Python - WHILE Loop
 
An Introduction To Python - Variables, Math
An Introduction To Python - Variables, MathAn Introduction To Python - Variables, Math
An Introduction To Python - Variables, Math
 
An Introduction To Python - Functions, Part 2
An Introduction To Python - Functions, Part 2An Introduction To Python - Functions, Part 2
An Introduction To Python - Functions, Part 2
 
An Introduction To Python - Files, Part 1
An Introduction To Python - Files, Part 1An Introduction To Python - Files, Part 1
An Introduction To Python - Files, Part 1
 
An Introduction To Software Development - Software Support and Maintenance
An Introduction To Software Development - Software Support and MaintenanceAn Introduction To Software Development - Software Support and Maintenance
An Introduction To Software Development - Software Support and Maintenance
 
An Introduction To Python - Dictionaries
An Introduction To Python - DictionariesAn Introduction To Python - Dictionaries
An Introduction To Python - Dictionaries
 
An Introduction To Python - Graphics
An Introduction To Python - GraphicsAn Introduction To Python - Graphics
An Introduction To Python - Graphics
 
An Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsAn Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List Algorithms
 
An Introduction To Python - FOR Loop
An Introduction To Python - FOR LoopAn Introduction To Python - FOR Loop
An Introduction To Python - FOR Loop
 
An Introduction To Python - Lists, Part 2
An Introduction To Python - Lists, Part 2An Introduction To Python - Lists, Part 2
An Introduction To Python - Lists, Part 2
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - Implementation
 

Similar to An Introduction To Python - Lists, Part 1

Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
Simplilearn
 
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptxCMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
deathlyfire321
 

Similar to An Introduction To Python - Lists, Part 1 (20)

AI_2nd Lab.pptx
AI_2nd Lab.pptxAI_2nd Lab.pptx
AI_2nd Lab.pptx
 
Programming in Python
Programming in Python Programming in Python
Programming in Python
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
Python programming
Python programmingPython programming
Python programming
 
CH05.ppt
CH05.pptCH05.ppt
CH05.ppt
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
 
updated_list.pptx
updated_list.pptxupdated_list.pptx
updated_list.pptx
 
Ch-8.pdf
Ch-8.pdfCh-8.pdf
Ch-8.pdf
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Python lists
Python listsPython lists
Python lists
 
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptxCMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
tupple.pptx
tupple.pptxtupple.pptx
tupple.pptx
 
Data structures
Data structuresData structures
Data structures
 
Week 1 - Data Structures and Algorithms
Week 1 - Data Structures and AlgorithmsWeek 1 - Data Structures and Algorithms
Week 1 - Data Structures and Algorithms
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

An Introduction To Python - Lists, Part 1

  • 1. An Introduction To Software Development Using Python Spring Semester, 2015 Class #9: Lists, Part 1
  • 2. Python Is All About Lists • What lists do you use in your life today? • Polytech Florida Common Prerequisites list of classes: Course ID, Course Name, Course Credits CHM 2045,Chemistry 1,3 CHM 2045L,Chemistry 1 Laboratory,1 COP 2271c,Introduction to Computation and Programming,3 EEL 3111c,Circuits 1,4 EEL 3112c,Circuits 2,3 MAC 2311,Analytic Geometry and Calculus 1,4 MAC 2312,Analytic Geometry and Calculus 2,4 MAC 2313,Analytic Geometry and Calculus 3,4 MAP 2302,Differential Equations,3 PHY 2048,Physics 1,3 PHY 2048L,Physics 1 Laboratory,1 PHY 2049,Physics 2,3 PHY 2049L,Physics 2 Laboratory,1 Image Credit: Clipart Panda
  • 3. 4 Steps To Creating A Python List 1. Convert each of the names into strings by surrounding the data with quotes. 2. Separate each of the list items from the next with a comma. 3. Surround the list of items with opening and closing square brackets. 4. Assign the list to an identifier (movies in the preceding code) using the assignment operator (=). “COP 2271c” “Introduction to Computation and Programming” 3 “COP 2271c”, “Introduction to Computation and Programming”, 3 [“COP 2271c”, “Introduction to Computation and Programming”, 3] prerequisites = [“COP 2271c”, “Introduction to Computation and Programming”, 3] COP 2271c Introduction to Computation and Programming 3 Image Credit: Clipart Panda1
  • 4. Python Is Different From Other Programing Languages! • Other languages (C, C++, Java, etc.) insist that every identifier used in code has type information declared for it. Not so with Python: identifiers are simply names that refer to a data object of some type. char example1; int example2 = 5; void example3(void) • One way to think of Python’s list is as a high-level collection. • The type of the data items is not important to the list. All Python needs to know is that you need a list, you’ve given it a name, and the list has some data items in it. Image Credit: Clipart Panda
  • 5. What Does Your List Look Like Inside Of The Computer? COP 2271c Introduction to Computation and Programming 3 0 1 2 Python Starts Counting At 0 Each item in a list has an index number associated with it… prerequisites = [“COP 2271c”, “Introduction to Computation and Programming”, 3] The computer stores your list data in what is called an “array”.
  • 6. How To Access A List • A list is a sequence of elements, each of which has an integer position or index. • To access a list element, you specify which index you want to use. • That is done with the subscript operator ([] ) in the same way that you access individual characters in a string. • For example: print(values[5]) # Prints the element at index 5 Image Credit: imgkid.com
  • 7. Access Your List Data Using The Square Bracket Notation print (prerequisites[0]) COP 2271c print (prerequisites[1]) Introduction to Computation and Programming print (prerequisites[2]) 3 Image Credit: Clipart Panda2
  • 8. You Can Create Multidimensional Lists • Lists can hold data of mixed type. • But it gets even better than that: lists can hold collections of anything, including other lists. • Simply embed the inner list within the enclosing list as needed. multiDim = [[123],[456],[789]] = 1 2 3 4 5 6 7 8 9 Image Credit: www.rafainspirationhomedecor.com3
  • 9. Programming Challenge • How many credits need to be taken to satisfy Poly prereqs? Image Credit: www.clker.com4
  • 10. Did You Know?: Accessing A List Backwards • Python, unlike many other languages, also allows you to use negative subscripts when accessing an element of a list. • The negative subscripts provide access to the list elements in reverse order. • For example, a subscript of –1 provides access to the last element in the list: last = values[-1] print("The last element in the list is", last) Image Credit: lessonpix.com
  • 11. What Is The Difference Between A List And A String? • Both lists and strings are sequences, and the [] operator can be used to access an element in any sequence. • There are two differences between lists and strings. – Lists can hold values of any type, whereas strings are sequences of characters. – Moreover, strings are immutable—you cannot change the characters in the sequence. But lists are mutable. You can replace one list element with another, like this: values[5] = 87 Image Credit: www.dreamstime.com
  • 12. What Happens When You Copy A List? Image Credit: imgkid.com
  • 13. Lists Are Much More Than Just Simple Arrays • Lists in Python are full-blown Python collection objects. • This means that lists come with ready-to-use functionality in the form of list methods. BIF len Methods 1. append 2. pop 3. remove 4. insert 5. extend Image Credit: besttoddlertoys.eu
  • 14. Playing With Lists: Append • Add teacher: Dr. Jim Anderson • Add year: 2015 Note: Python lists can contain data of mixed types. You can mix strings with numbers within the same Python list. You can mix more than just strings and numbers -- you can store data of any type in a single list. prerequisites = [“COP 2271c”, “Introduction to Computation and Programming”, 3] Image Credit: ClipArt Best5
  • 15. Playing With Lists: Pop • Allows you to remove the item that is at the end of a list prereqs[course].pop() CHM 2045 , Chemistry 1 , 3 , Dr. Anderson , 2015 X Image Credit: blog.poolproducts.com6
  • 16. Playing With Lists: Remove • Allows you to specify which list item you want to remove no matter where in the list it is located prereqs[course].remove("Dr. Anderson") CHM 2045 , Chemistry 1 , 3 , Dr. AndersonX Image Credit: www.pinterest.com7
  • 17. Playing With Lists: Insert • Allows you to add an item to a list in a specified location on the list prereqs[course].insert(2,"Really Hard") CHM 2045 , Chemistry 1 , Really Hard , 3 Image Credit: ekskavatör8
  • 18. Playing With Lists: Extend • Allows multiple list items to be added to an existing list prereqs[course].extend(["Dr. Anderson", "2015"]) CHM 2045 , Chemistry 1 , Really Hard , 3 , Dr. Anderson , 2015 Image Credit: www.clipartpanda.com9
  • 19. What’s In Your Python Toolbox? print() math strings I/O IF/Else elif While For Lists
  • 20. What We Covered Today 1. Lists 2. Multidimensional lists Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
  • 21. What We’ll Be Covering Next Time 1. Lists, Part 2 Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

Editor's Notes

  1. New name for the class I know what this means Technical professionals are who get hired This means much more than just having a narrow vertical knowledge of some subject area. It means that you know how to produce an outcome that I value. I’m willing to pay you to do that.