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)

Python lists
Python listsPython lists
Python lists
Smt. Indira Gandhi College of Engineering, Navi Mumbai, Mumbai
 
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
 
pyton Notes6
 pyton Notes6 pyton Notes6
pyton Notes6
Amba Research
 
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
 
Programming in Python Lists and its methods .ppt
Programming in Python Lists and its methods .pptProgramming in Python Lists and its methods .ppt
Programming in Python Lists and its methods .ppt
Dr. Jasmine Beulah Gnanadurai
 
List In Python Programming. The linked list
List In Python Programming. The linked listList In Python Programming. The linked list
List In Python Programming. The linked list
bestbuddiesofgcs
 
Python for the data science most in cse.pptx
Python for the data science most in cse.pptxPython for the data science most in cse.pptx
Python for the data science most in cse.pptx
Rajasekhar364622
 
Python _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functionsPython _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functions
VidhyaB10
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
Guru Nanak Technical Institutions
 
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 tuple dictionary .pptx
Python list tuple dictionary       .pptxPython list tuple dictionary       .pptx
Python list tuple dictionary .pptx
miteshchaudhari4466
 
Brief Explanation On List and Dictionaries of Python
Brief Explanation On List and Dictionaries of PythonBrief Explanation On List and Dictionaries of Python
Brief Explanation On List and Dictionaries of Python
nikhita4775
 
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 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
 
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
 
List In Python Programming. The linked list
List In Python Programming. The linked listList In Python Programming. The linked list
List In Python Programming. The linked list
bestbuddiesofgcs
 
Python for the data science most in cse.pptx
Python for the data science most in cse.pptxPython for the data science most in cse.pptx
Python for the data science most in cse.pptx
Rajasekhar364622
 
Python _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functionsPython _dataStructures_ List, Tuples, its functions
Python _dataStructures_ List, Tuples, its functions
VidhyaB10
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
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
 
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 tuple dictionary .pptx
Python list tuple dictionary       .pptxPython list tuple dictionary       .pptx
Python list tuple dictionary .pptx
miteshchaudhari4466
 
Brief Explanation On List and Dictionaries of Python
Brief Explanation On List and Dictionaries of PythonBrief Explanation On List and Dictionaries of Python
Brief Explanation On List and Dictionaries of Python
nikhita4775
 
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
 
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)

Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
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
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
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
 
zOS CommServer support for the Network Express feature on z17
zOS CommServer support for the Network Express feature on z17zOS CommServer support for the Network Express feature on z17
zOS CommServer support for the Network Express feature on z17
zOSCommserver
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
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
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
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
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Scalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple DevicesScalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple Devices
Scalefusion
 
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
 
The rise of e-commerce has redefined how retailers operate—and reconciliation...
The rise of e-commerce has redefined how retailers operate—and reconciliation...The rise of e-commerce has redefined how retailers operate—and reconciliation...
The rise of e-commerce has redefined how retailers operate—and reconciliation...
Prachi Desai
 
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
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
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
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
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
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
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
 
zOS CommServer support for the Network Express feature on z17
zOS CommServer support for the Network Express feature on z17zOS CommServer support for the Network Express feature on z17
zOS CommServer support for the Network Express feature on z17
zOSCommserver
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
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
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
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
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Scalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple DevicesScalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple Devices
Scalefusion
 
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
 
The rise of e-commerce has redefined how retailers operate—and reconciliation...
The rise of e-commerce has redefined how retailers operate—and reconciliation...The rise of e-commerce has redefined how retailers operate—and reconciliation...
The rise of e-commerce has redefined how retailers operate—and reconciliation...
Prachi Desai
 
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
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
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
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 

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]