SlideShare a Scribd company logo
Introduction to 
Programming with 
Python – Class 4 
SYED FARJAD ZIA ZAIDI
Class Objectives 
Class Objective 
Understanding Lists 
Write few simple programs that use lists.
Class Material 
•Chapter 6, 8 - 
Python for 
Informatics: 
Exploring 
Information 
Reading
Lists 
 The most basic data structure in Python is the sequence. 
Each element of a sequence is assigned a number - its 
position or index. The first index is zero, the second index 
is one, and so forth. 
 Python has six built-in types of sequences, but the most 
common ones are lists and tuples, which we would see 
in this tutorial. 
 There are certain things you can do with all sequence 
types. These operations include indexing, slicing, adding, 
multiplying, and checking for membership. In addition, 
Python has built-in functions for finding the length of a 
sequence and for finding its largest and smallest 
elements.
Creating Lists 
 Creating a list is as simple as putting different comma-separated 
values between squere brackets. For example: 
list1 = ['physics', 'chemistry', 1997, 2000]; 
list2 = [1, 2, 3, 4, 5 ]; 
list3 = ["a", "b", "c", "d"];
Accessing Values in Lists: 
 To access values in lists, use the square brackets for slicing along 
with the index or indices to obtain value available at that index. 
Following is a simple example: 
list1 = ['physics', 'chemistry', 1997, 2000]; 
list2 = [1, 2, 3, 4, 5, 6, 7 ]; 
print "list1[0]: ", list1[0] 
print "list2[1:5]: ", list2[1:5]
Updating Lists 
 You can update single or multiple elements of lists by giving the slice 
on the left-hand side of the assignment operator, and you can add 
to elements in a list with the append() method. Following is a simple 
example: 
list = ['physics', 'chemistry', 1997, 2000]; 
print "Value available at index 2 : " 
print list[2]; 
list[2] = 2001; 
print "New value available at index 2 : " 
print list[2];
Delete Lists Elements 
 To remove a list element, you can use either the del statement if you 
know exactly which element(s) you are deleting or the remove() 
method if you do not know. Following is a simple example: 
list1 = ['physics', 'chemistry', 1997, 2000]; 
print list1; 
del list1[2]; 
print "After deleting value at index 2 : " 
print list1;
Basic List Operations 
 Lists respond to the + and * operators much like strings; they mean 
concatenation and repetition here too, except that the result is a 
new list, not a string. 
 In fact, lists respond to all of the general sequence operations we 
used on strings in the prior chapter.
List Operations 
Python Expression Results Description 
len([1, 2, 3]) 3 Length 
[1, 2, 3] + [4, 5, 6] [1, 2, 3, 4, 5, 6] Concatenation 
['Hi!'] * 4 ['Hi!', 'Hi!', 'Hi!', 'Hi!'] Repetition 
3 in [1, 2, 3] True Membership 
for x in [1, 2, 3]: print x, 1 2 3 Iteration
Exercise 0 
 Create a program that will keep track of items for a shopping list. 
The program should keep asking for new items until nothing is 
entered (no input followed by enter/return key). The program should 
then display the full shopping list.
Exercise 1 
 Given an array of ints, return True if 6 appears as either the first or last 
element in the array. The array will be length 1 or more. 
first_last6([1, 2, 6]) → True 
first_last6([6, 1, 2, 3]) → True 
first_last6([13, 6, 1, 2, 3]) → False
Exercise 2 
 Given an array of ints, return True if the array is length 1 or more, and 
the first element and the last element are equal. 
same_first_last([1, 2, 3]) → False 
same_first_last([1, 2, 3, 1]) → True 
same_first_last([1, 2, 1]) → True
Exercise 3 
 Return the number of even ints in the given array. Note: the % "mod" 
operator computes the remainder, e.g. 5 % 2 is 1. 
count_evens([2, 1, 2, 3, 4]) → 3 
count_evens([2, 2, 0]) → 3 
count_evens([1, 3, 5]) → 0
Any Queries? 
 Link to Facebook Group: 
https://www.facebook.com/groups/introtopython.iccbs/ 
 Email: 
farjad_bullet@rocketmail.com

More Related Content

What's hot

Intro To BOOST.Spirit
Intro To BOOST.SpiritIntro To BOOST.Spirit
Intro To BOOST.Spirit
Will Shen
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
amiable_indian
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arraysphanleson
 
Python second ppt
Python second pptPython second ppt
Python second ppt
RaginiJain21
 
Data types in python
Data types in pythonData types in python
Data types in python
Learnbay Datascience
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
tanmaymodi4
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
Sushant Mane
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete  Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete
Adnan abid
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
Praveen M Jigajinni
 
Python data type
Python data typePython data type
Python data type
nuripatidar
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad
 
Data types in python lecture (2)
Data types in python lecture (2)Data types in python lecture (2)
Data types in python lecture (2)
Ali ٍSattar
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
Mr. Vikram Singh Slathia
 

What's hot (15)

Intro To BOOST.Spirit
Intro To BOOST.SpiritIntro To BOOST.Spirit
Intro To BOOST.Spirit
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 
Python second ppt
Python second pptPython second ppt
Python second ppt
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete  Database structure Structures Link list and trees and Recurison complete
Database structure Structures Link list and trees and Recurison complete
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
 
Python data type
Python data typePython data type
Python data type
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Data types in python lecture (2)
Data types in python lecture (2)Data types in python lecture (2)
Data types in python lecture (2)
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 

Viewers also liked

Clase 2 estatica
Clase 2 estatica Clase 2 estatica
Clase 2 estatica
Gerald Moreira Ramírez
 
Substituting HDF5 tools with Python/H5py scripts
Substituting HDF5 tools with Python/H5py scriptsSubstituting HDF5 tools with Python/H5py scripts
Substituting HDF5 tools with Python/H5py scripts
The HDF-EOS Tools and Information Center
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Logic Over Language
Logic Over LanguageLogic Over Language
Logic Over Language
Purple, Rock, Scissors
 
Python and HDF5: Overview
Python and HDF5: OverviewPython and HDF5: Overview
Python and HDF5: Overview
andrewcollette
 
Introduction to Databases
Introduction to DatabasesIntroduction to Databases
Introduction to Databases
Syed Farjad Zia Zaidi
 
Logic: Language and Information 1
Logic: Language and Information 1Logic: Language and Information 1
Logic: Language and Information 1
Syed Farjad Zia Zaidi
 
An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-5
Introduction To Programming with Python-5Introduction To Programming with Python-5
Introduction To Programming with Python-5
Syed Farjad Zia Zaidi
 
Introduction to UBI
Introduction to UBIIntroduction to UBI
Introduction to UBIRoy Lee
 
Python 4 Arc
Python 4 ArcPython 4 Arc
Python 4 Arc
absvis
 
The Python Programming Language and HDF5: H5Py
The Python Programming Language and HDF5: H5PyThe Python Programming Language and HDF5: H5Py
The Python Programming Language and HDF5: H5Py
The HDF-EOS Tools and Information Center
 
Estática aplicada a las construcciones de edificaciones modernas
Estática aplicada a las construcciones de edificaciones modernas  Estática aplicada a las construcciones de edificaciones modernas
Estática aplicada a las construcciones de edificaciones modernas
eduardo rivera romero
 
HDF5 Tools
HDF5 ToolsHDF5 Tools
Python programming - Everyday(ish) Examples
Python programming - Everyday(ish) ExamplesPython programming - Everyday(ish) Examples
Python programming - Everyday(ish) Examples
Ashish Sharma
 
Lets learn Python !
Lets learn Python !Lets learn Python !
Lets learn Python !
Kiran Gangadharan
 

Viewers also liked (20)

Clase 2 estatica
Clase 2 estatica Clase 2 estatica
Clase 2 estatica
 
Substituting HDF5 tools with Python/H5py scripts
Substituting HDF5 tools with Python/H5py scriptsSubstituting HDF5 tools with Python/H5py scripts
Substituting HDF5 tools with Python/H5py scripts
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
 
Logic Over Language
Logic Over LanguageLogic Over Language
Logic Over Language
 
Python and HDF5: Overview
Python and HDF5: OverviewPython and HDF5: Overview
Python and HDF5: Overview
 
Introduction to Databases
Introduction to DatabasesIntroduction to Databases
Introduction to Databases
 
Logic: Language and Information 1
Logic: Language and Information 1Logic: Language and Information 1
Logic: Language and Information 1
 
An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013
 
Introduction To Programming with Python-5
Introduction To Programming with Python-5Introduction To Programming with Python-5
Introduction To Programming with Python-5
 
Unidad 1 fisica
Unidad 1 fisicaUnidad 1 fisica
Unidad 1 fisica
 
Introduction to UBI
Introduction to UBIIntroduction to UBI
Introduction to UBI
 
Python 4 Arc
Python 4 ArcPython 4 Arc
Python 4 Arc
 
The Python Programming Language and HDF5: H5Py
The Python Programming Language and HDF5: H5PyThe Python Programming Language and HDF5: H5Py
The Python Programming Language and HDF5: H5Py
 
Estática aplicada a las construcciones de edificaciones modernas
Estática aplicada a las construcciones de edificaciones modernas  Estática aplicada a las construcciones de edificaciones modernas
Estática aplicada a las construcciones de edificaciones modernas
 
Estática.pdf
Estática.pdfEstática.pdf
Estática.pdf
 
Using HDF5 and Python: The H5py module
Using HDF5 and Python: The H5py moduleUsing HDF5 and Python: The H5py module
Using HDF5 and Python: The H5py module
 
HDF5 Tools
HDF5 ToolsHDF5 Tools
HDF5 Tools
 
Python programming - Everyday(ish) Examples
Python programming - Everyday(ish) ExamplesPython programming - Everyday(ish) Examples
Python programming - Everyday(ish) Examples
 
2 unidad estatica (1)
2 unidad estatica (1)2 unidad estatica (1)
2 unidad estatica (1)
 
Lets learn Python !
Lets learn Python !Lets learn Python !
Lets learn Python !
 

Similar to Introduction To Programming with Python-4

Python PRACTICAL NO 6 for your Assignment.pptx
Python PRACTICAL NO 6 for your Assignment.pptxPython PRACTICAL NO 6 for your Assignment.pptx
Python PRACTICAL NO 6 for your Assignment.pptx
NeyXmarXd
 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptx
MURADSANJOUM
 
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
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
Asst.prof M.Gokilavani
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
List in Python
List in PythonList in Python
List in Python
Sharath Ankrajegowda
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
Celine George
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
Praveen M Jigajinni
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189
Mahmoud Samir Fayed
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
AnitaDevi158873
 
The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212
Mahmoud Samir Fayed
 
Python list
Python listPython list
Python - Data Collection
Python - Data CollectionPython - Data Collection
Python - Data Collection
JoseTanJr
 
Python data handling notes
Python data handling notesPython data handling notes
Python data handling notes
Prof. Dr. K. Adisesha
 
Lists
ListsLists
updated_list.pptx
updated_list.pptxupdated_list.pptx
updated_list.pptx
Koteswari Kasireddy
 
Data Structure Searching.pptx
Data Structure Searching.pptxData Structure Searching.pptx
Data Structure Searching.pptx
SourabhTaneja4
 

Similar to Introduction To Programming with Python-4 (20)

Python lists
Python listsPython lists
Python lists
 
Python PRACTICAL NO 6 for your Assignment.pptx
Python PRACTICAL NO 6 for your Assignment.pptxPython PRACTICAL NO 6 for your Assignment.pptx
Python PRACTICAL NO 6 for your Assignment.pptx
 
pyton Notes6
 pyton Notes6 pyton Notes6
pyton Notes6
 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.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
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
 
List in Python
List in PythonList in Python
List in Python
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212
 
Python list
Python listPython list
Python list
 
Python - Data Collection
Python - Data CollectionPython - Data Collection
Python - Data Collection
 
Python data handling notes
Python data handling notesPython data handling notes
Python data handling notes
 
Lists
ListsLists
Lists
 
updated_list.pptx
updated_list.pptxupdated_list.pptx
updated_list.pptx
 
Data Structure Searching.pptx
Data Structure Searching.pptxData Structure Searching.pptx
Data Structure Searching.pptx
 

More from Syed Farjad Zia Zaidi

Vision & sight
Vision & sightVision & sight
Vision & sight
Syed Farjad Zia Zaidi
 
Introduction to Computing with Java
Introduction to Computing with JavaIntroduction to Computing with Java
Introduction to Computing with Java
Syed Farjad Zia Zaidi
 
Web Application Architectures
Web Application ArchitecturesWeb Application Architectures
Web Application Architectures
Syed Farjad Zia Zaidi
 
Foundations of Virtual Instruction
Foundations of Virtual InstructionFoundations of Virtual Instruction
Foundations of Virtual Instruction
Syed Farjad Zia Zaidi
 
Programming for Everybody (Python)
Programming for Everybody (Python)Programming for Everybody (Python)
Programming for Everybody (Python)
Syed Farjad Zia Zaidi
 
Learn to Program: The Fundamentals
Learn to Program: The FundamentalsLearn to Program: The Fundamentals
Learn to Program: The Fundamentals
Syed Farjad Zia Zaidi
 
Introduction to Systematic Program Design - Part 1
Introduction to Systematic Program Design - Part 1Introduction to Systematic Program Design - Part 1
Introduction to Systematic Program Design - Part 1
Syed Farjad Zia Zaidi
 
Emerging Trends & Technologies in the Virtual K-12 Classroom
Emerging Trends & Technologies in the Virtual K-12 ClassroomEmerging Trends & Technologies in the Virtual K-12 Classroom
Emerging Trends & Technologies in the Virtual K-12 Classroom
Syed Farjad Zia Zaidi
 
An Introduction to Interactive Programming in Python 2014
An Introduction to Interactive Programming in Python 2014An Introduction to Interactive Programming in Python 2014
An Introduction to Interactive Programming in Python 2014
Syed Farjad Zia Zaidi
 
Internet History, Technology, and Security
Internet History, Technology, and SecurityInternet History, Technology, and Security
Internet History, Technology, and Security
Syed Farjad Zia Zaidi
 
Human-Computer Interaction
Human-Computer InteractionHuman-Computer Interaction
Human-Computer Interaction
Syed Farjad Zia Zaidi
 
Beginning Game Programming with C#
Beginning Game Programming with C#Beginning Game Programming with C#
Beginning Game Programming with C#
Syed Farjad Zia Zaidi
 
Programming Mobile Applications for Android Handheld Systems 2014
Programming Mobile Applications for Android Handheld Systems 2014Programming Mobile Applications for Android Handheld Systems 2014
Programming Mobile Applications for Android Handheld Systems 2014
Syed Farjad Zia Zaidi
 
Computer Science 101
Computer Science 101Computer Science 101
Computer Science 101
Syed Farjad Zia Zaidi
 
Software Requirement Specification - Software Pack Solution 14
Software Requirement Specification - Software Pack Solution 14Software Requirement Specification - Software Pack Solution 14
Software Requirement Specification - Software Pack Solution 14
Syed Farjad Zia Zaidi
 
Project Proposal - Software Pack Solution 14
Project Proposal - Software Pack Solution 14Project Proposal - Software Pack Solution 14
Project Proposal - Software Pack Solution 14
Syed Farjad Zia Zaidi
 
Database Diagram Tutorial-SQL Server 2012
Database Diagram Tutorial-SQL Server 2012Database Diagram Tutorial-SQL Server 2012
Database Diagram Tutorial-SQL Server 2012
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
MindMuscle Xtreme
MindMuscle XtremeMindMuscle Xtreme
MindMuscle Xtreme
Syed Farjad Zia Zaidi
 
How to connect database file to a 3-Tier Architecture Application and obtain ...
How to connect database file to a 3-Tier Architecture Application and obtain ...How to connect database file to a 3-Tier Architecture Application and obtain ...
How to connect database file to a 3-Tier Architecture Application and obtain ...
Syed Farjad Zia Zaidi
 

More from Syed Farjad Zia Zaidi (20)

Vision & sight
Vision & sightVision & sight
Vision & sight
 
Introduction to Computing with Java
Introduction to Computing with JavaIntroduction to Computing with Java
Introduction to Computing with Java
 
Web Application Architectures
Web Application ArchitecturesWeb Application Architectures
Web Application Architectures
 
Foundations of Virtual Instruction
Foundations of Virtual InstructionFoundations of Virtual Instruction
Foundations of Virtual Instruction
 
Programming for Everybody (Python)
Programming for Everybody (Python)Programming for Everybody (Python)
Programming for Everybody (Python)
 
Learn to Program: The Fundamentals
Learn to Program: The FundamentalsLearn to Program: The Fundamentals
Learn to Program: The Fundamentals
 
Introduction to Systematic Program Design - Part 1
Introduction to Systematic Program Design - Part 1Introduction to Systematic Program Design - Part 1
Introduction to Systematic Program Design - Part 1
 
Emerging Trends & Technologies in the Virtual K-12 Classroom
Emerging Trends & Technologies in the Virtual K-12 ClassroomEmerging Trends & Technologies in the Virtual K-12 Classroom
Emerging Trends & Technologies in the Virtual K-12 Classroom
 
An Introduction to Interactive Programming in Python 2014
An Introduction to Interactive Programming in Python 2014An Introduction to Interactive Programming in Python 2014
An Introduction to Interactive Programming in Python 2014
 
Internet History, Technology, and Security
Internet History, Technology, and SecurityInternet History, Technology, and Security
Internet History, Technology, and Security
 
Human-Computer Interaction
Human-Computer InteractionHuman-Computer Interaction
Human-Computer Interaction
 
Beginning Game Programming with C#
Beginning Game Programming with C#Beginning Game Programming with C#
Beginning Game Programming with C#
 
Programming Mobile Applications for Android Handheld Systems 2014
Programming Mobile Applications for Android Handheld Systems 2014Programming Mobile Applications for Android Handheld Systems 2014
Programming Mobile Applications for Android Handheld Systems 2014
 
Computer Science 101
Computer Science 101Computer Science 101
Computer Science 101
 
Software Requirement Specification - Software Pack Solution 14
Software Requirement Specification - Software Pack Solution 14Software Requirement Specification - Software Pack Solution 14
Software Requirement Specification - Software Pack Solution 14
 
Project Proposal - Software Pack Solution 14
Project Proposal - Software Pack Solution 14Project Proposal - Software Pack Solution 14
Project Proposal - Software Pack Solution 14
 
Database Diagram Tutorial-SQL Server 2012
Database Diagram Tutorial-SQL Server 2012Database Diagram Tutorial-SQL Server 2012
Database Diagram Tutorial-SQL Server 2012
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
MindMuscle Xtreme
MindMuscle XtremeMindMuscle Xtreme
MindMuscle Xtreme
 
How to connect database file to a 3-Tier Architecture Application and obtain ...
How to connect database file to a 3-Tier Architecture Application and obtain ...How to connect database file to a 3-Tier Architecture Application and obtain ...
How to connect database file to a 3-Tier Architecture Application and obtain ...
 

Recently uploaded

Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 

Recently uploaded (20)

Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 

Introduction To Programming with Python-4

  • 1. Introduction to Programming with Python – Class 4 SYED FARJAD ZIA ZAIDI
  • 2. Class Objectives Class Objective Understanding Lists Write few simple programs that use lists.
  • 3. Class Material •Chapter 6, 8 - Python for Informatics: Exploring Information Reading
  • 4. Lists  The most basic data structure in Python is the sequence. Each element of a sequence is assigned a number - its position or index. The first index is zero, the second index is one, and so forth.  Python has six built-in types of sequences, but the most common ones are lists and tuples, which we would see in this tutorial.  There are certain things you can do with all sequence types. These operations include indexing, slicing, adding, multiplying, and checking for membership. In addition, Python has built-in functions for finding the length of a sequence and for finding its largest and smallest elements.
  • 5. Creating Lists  Creating a list is as simple as putting different comma-separated values between squere brackets. For example: list1 = ['physics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3, 4, 5 ]; list3 = ["a", "b", "c", "d"];
  • 6. Accessing Values in Lists:  To access values in lists, use the square brackets for slicing along with the index or indices to obtain value available at that index. Following is a simple example: list1 = ['physics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3, 4, 5, 6, 7 ]; print "list1[0]: ", list1[0] print "list2[1:5]: ", list2[1:5]
  • 7. Updating Lists  You can update single or multiple elements of lists by giving the slice on the left-hand side of the assignment operator, and you can add to elements in a list with the append() method. Following is a simple example: list = ['physics', 'chemistry', 1997, 2000]; print "Value available at index 2 : " print list[2]; list[2] = 2001; print "New value available at index 2 : " print list[2];
  • 8. Delete Lists Elements  To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting or the remove() method if you do not know. Following is a simple example: list1 = ['physics', 'chemistry', 1997, 2000]; print list1; del list1[2]; print "After deleting value at index 2 : " print list1;
  • 9. Basic List Operations  Lists respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new list, not a string.  In fact, lists respond to all of the general sequence operations we used on strings in the prior chapter.
  • 10. List Operations Python Expression Results Description len([1, 2, 3]) 3 Length [1, 2, 3] + [4, 5, 6] [1, 2, 3, 4, 5, 6] Concatenation ['Hi!'] * 4 ['Hi!', 'Hi!', 'Hi!', 'Hi!'] Repetition 3 in [1, 2, 3] True Membership for x in [1, 2, 3]: print x, 1 2 3 Iteration
  • 11. Exercise 0  Create a program that will keep track of items for a shopping list. The program should keep asking for new items until nothing is entered (no input followed by enter/return key). The program should then display the full shopping list.
  • 12. Exercise 1  Given an array of ints, return True if 6 appears as either the first or last element in the array. The array will be length 1 or more. first_last6([1, 2, 6]) → True first_last6([6, 1, 2, 3]) → True first_last6([13, 6, 1, 2, 3]) → False
  • 13. Exercise 2  Given an array of ints, return True if the array is length 1 or more, and the first element and the last element are equal. same_first_last([1, 2, 3]) → False same_first_last([1, 2, 3, 1]) → True same_first_last([1, 2, 1]) → True
  • 14. Exercise 3  Return the number of even ints in the given array. Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1. count_evens([2, 1, 2, 3, 4]) → 3 count_evens([2, 2, 0]) → 3 count_evens([1, 3, 5]) → 0
  • 15. Any Queries?  Link to Facebook Group: https://www.facebook.com/groups/introtopython.iccbs/  Email: farjad_bullet@rocketmail.com