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 (15)

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 Arrays
phanleson
 
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
 
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 Arrays
phanleson
 
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
 
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
 

Viewers also liked (20)

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
 
Unidad 1 fisica
Unidad 1 fisicaUnidad 1 fisica
Unidad 1 fisica
Gabino Osmar Ibañez Tiol
 
Introduction to UBI
Introduction to UBIIntroduction to UBI
Introduction to UBI
Roy 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
 
Estática.pdf
Estática.pdfEstática.pdf
Estática.pdf
Danitza Araya Lopez
 
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
The HDF-EOS Tools and Information Center
 
HDF5 Tools
HDF5 ToolsHDF5 Tools
HDF5 Tools
The HDF-EOS Tools and Information Center
 
Python programming - Everyday(ish) Examples
Python programming - Everyday(ish) ExamplesPython programming - Everyday(ish) Examples
Python programming - Everyday(ish) Examples
Ashish Sharma
 
2 unidad estatica (1)
2 unidad estatica (1)2 unidad estatica (1)
2 unidad estatica (1)
jorge.zaragoza12
 
Lets learn Python !
Lets learn Python !Lets learn Python !
Lets learn Python !
Kiran Gangadharan
 
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
 
Python and HDF5: Overview
Python and HDF5: OverviewPython and HDF5: Overview
Python and HDF5: Overview
andrewcollette
 
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 UBI
Roy Lee
 
Python 4 Arc
Python 4 ArcPython 4 Arc
Python 4 Arc
absvis
 
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
 
Python programming - Everyday(ish) Examples
Python programming - Everyday(ish) ExamplesPython programming - Everyday(ish) Examples
Python programming - Everyday(ish) Examples
Ashish Sharma
 
Ad

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

UNIT-3 python and data structure alo.pptx
UNIT-3 python and data structure alo.pptxUNIT-3 python and data structure alo.pptx
UNIT-3 python and data structure alo.pptx
harikahhy
 
Python _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functionsPython _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functions
VidhyaB10
 
"Automata Basics and Python Applications"
"Automata Basics and Python Applications""Automata Basics and Python Applications"
"Automata Basics and Python Applications"
ayeshasiraj34
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
Guru Nanak Technical Institutions
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 english
ssuser442080
 
Python3
Python3Python3
Python3
Sourodip Kundu
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
AnitaDevi158873
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
Gil Cohen
 
ComandosDePython_ComponentesBasicosImpl.ppt
ComandosDePython_ComponentesBasicosImpl.pptComandosDePython_ComponentesBasicosImpl.ppt
ComandosDePython_ComponentesBasicosImpl.ppt
oscarJulianPerdomoCh1
 
PROBLEM SOLVING AND PYTHON PROGRAMMING PPT
PROBLEM SOLVING AND PYTHON PROGRAMMING PPTPROBLEM SOLVING AND PYTHON PROGRAMMING PPT
PROBLEM SOLVING AND PYTHON PROGRAMMING PPT
MulliMary
 
Python_ 3 CheatSheet
Python_ 3 CheatSheetPython_ 3 CheatSheet
Python_ 3 CheatSheet
Dr. Volkan OBAN
 
Python programming
Python programmingPython programming
Python programming
sirikeshava
 
Pythonlearn-08-Lists for fundatmentals of Programming
Pythonlearn-08-Lists for fundatmentals of ProgrammingPythonlearn-08-Lists for fundatmentals of Programming
Pythonlearn-08-Lists for fundatmentals of Programming
ABIGAILJUDITHPETERPR
 
Intro Python Data Structures.pptx Intro Python Data Structures.pptx
Intro Python Data Structures.pptx Intro Python Data Structures.pptxIntro Python Data Structures.pptx Intro Python Data Structures.pptx
Intro Python Data Structures.pptx Intro Python Data Structures.pptx
judyhilly13
 
fundamental of python --- vivek singh shekawat
fundamental  of python --- vivek singh shekawatfundamental  of python --- vivek singh shekawat
fundamental of python --- vivek singh shekawat
shekhawatasshp
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 english
yassminkhaldi1
 
Pytho lists
Pytho listsPytho lists
Pytho lists
BMS Institute of Technology and Management
 
Unit 4.pptx python list tuples dictionary
Unit 4.pptx python list tuples dictionaryUnit 4.pptx python list tuples dictionary
Unit 4.pptx python list tuples dictionary
shakthi10
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology Initiative
Basil Bibi
 
UNIT-3 python and data structure alo.pptx
UNIT-3 python and data structure alo.pptxUNIT-3 python and data structure alo.pptx
UNIT-3 python and data structure alo.pptx
harikahhy
 
Python _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functionsPython _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functions
VidhyaB10
 
"Automata Basics and Python Applications"
"Automata Basics and Python Applications""Automata Basics and Python Applications"
"Automata Basics and Python Applications"
ayeshasiraj34
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 english
ssuser442080
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
MihirDatir
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
Gil Cohen
 
ComandosDePython_ComponentesBasicosImpl.ppt
ComandosDePython_ComponentesBasicosImpl.pptComandosDePython_ComponentesBasicosImpl.ppt
ComandosDePython_ComponentesBasicosImpl.ppt
oscarJulianPerdomoCh1
 
PROBLEM SOLVING AND PYTHON PROGRAMMING PPT
PROBLEM SOLVING AND PYTHON PROGRAMMING PPTPROBLEM SOLVING AND PYTHON PROGRAMMING PPT
PROBLEM SOLVING AND PYTHON PROGRAMMING PPT
MulliMary
 
Python programming
Python programmingPython programming
Python programming
sirikeshava
 
Pythonlearn-08-Lists for fundatmentals of Programming
Pythonlearn-08-Lists for fundatmentals of ProgrammingPythonlearn-08-Lists for fundatmentals of Programming
Pythonlearn-08-Lists for fundatmentals of Programming
ABIGAILJUDITHPETERPR
 
Intro Python Data Structures.pptx Intro Python Data Structures.pptx
Intro Python Data Structures.pptx Intro Python Data Structures.pptxIntro Python Data Structures.pptx Intro Python Data Structures.pptx
Intro Python Data Structures.pptx Intro Python Data Structures.pptx
judyhilly13
 
fundamental of python --- vivek singh shekawat
fundamental  of python --- vivek singh shekawatfundamental  of python --- vivek singh shekawat
fundamental of python --- vivek singh shekawat
shekhawatasshp
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 english
yassminkhaldi1
 
Unit 4.pptx python list tuples dictionary
Unit 4.pptx python list tuples dictionaryUnit 4.pptx python list tuples dictionary
Unit 4.pptx python list tuples dictionary
shakthi10
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology Initiative
Basil Bibi
 
Ad

More from Syed Farjad Zia Zaidi (20)

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
 
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
 
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
 
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
 
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
 

Recently uploaded (20)

Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Prachi Desai
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
Bonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdfBonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdf
Herond Labs
 
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Why Indonesia’s $12.63B Alt-Lending Boom Needs Loan Servicing Automation & Re...
Prachi Desai
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
Bonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdfBonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdf
Herond Labs
 

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: [email protected]