SlideShare a Scribd company logo
Introduction to 
Programming with 
Python – Class 3 
SYED FARJAD ZIA ZAIDI
Class Objectives 
Class Objective 
Understanding Strings and some useful string operations. 
Write few simple programs that use string functions and lists.
Class Material 
•Chapter 6, 8 - 
Python for 
Informatics: 
Exploring 
Information 
Reading
Strings 
 Strings are amongst the most popular types in 
Python. We can create them simply by 
enclosing characters in quotes. Python treats 
single quotes the same as double quotes. 
 Creating strings is as simple as assigning a value 
to a variable. For example: 
message = “Hello World”
Introduction to Indexing 
 Strings can be divided into substrings using indexing. 
 To access substrings, use the square brackets for slicing along with 
the index or indices to obtain your substring, this is called Indexing. 
Following is a simple example: 
message = 'Hello World!' 
messageTwo = "Python Programming" 
print "var1[0]: ", message[0] 
print "var2[1:5]: ", messageTwo[1:5]
String Concatenation 
 String concatenation is a process in which two strings are merged 
together. Concatenation is very simple and uses the operator ‘+’ to 
concatenate. 
For Example: 
message = “Hello” 
messageTwo = “ “ 
messageThree = “World” 
print message + messageTwo + messageThree
Escape Characters 
 Following table is a list of commonly used escape or non-printable 
characters that can be represented with backslash notation. 
An escape character gets interpreted; in a single quoted as well as 
double quoted strings. 
Backslash Notation Description 
n New Line 
t Space 
s Tab
String Special Operators 
+ 
•Concatenation - 
Adds values on 
either side of the 
operator 
* 
•Repetition - 
Creates new 
strings, 
concatenating 
multiple copies of 
the same string
Python Comparison Operators 
[] 
• Slice - Gives the character from the given index 
[ : ] 
•Range Slice - Gives the characters from the 
given range
Python Comparison Operators 
in 
• Membership - Returns true if a character 
exists in the given string 
not in 
• Membership - Returns true if a character 
does not exist in the given string
Python Triple Quotes 
 Python's triple quotes comes to the rescue by allowing strings to 
span multiple lines, including verbatim NEWLINEs, TABs, and any 
other special characters.
String Functions: 
Method Description 
capitalize() Capitalizes first letter of string 
count(str, beg=0, end=len(string)) Counts how many times str occurs in 
string or in a substring of string if 
starting index beg and ending index 
end are given 
find(str, beg=0, end=len(string)) Determine if str occurs in string or in a 
substring of string if starting index beg 
and ending index end are given 
returns index if found and -1 otherwise 
index(str, beg=0, end=len(string)) Same as find(), but raises an error if str 
not found 
len(string) Returns the length of the string
String Functions: 
 Go to the following link for more string functions: 
http://www.tutorialspoint.com/python/python_strings.htm 
 You can also find string functions by writing the following in the 
python IDLE 
help(str)
Exercise 1 
 Write code using find() and string slicing to extract the number at 
the end of the line below. Convert the extracted value to a floating 
point number and print it out. 
text = "X-DSPAM-Confidence: 0.8475";
Exercise 2 
 Given a string and a non-negative int n, return a larger string that is n 
copies of the original string. 
string_times('Hi', 2) → 'HiHi' 
string_times('Hi', 3) → 'HiHiHi' 
string_times('Hi', 1) → 'Hi'
Exercise 3 
 Given a string, return a string where for every char in the original, there 
are two chars. 
double_char('The') → 'TThhee' 
double_char('AAbb') → 'AAAAbbbb' 
double_char('Hi-There') → 'HHii--TThheerree'
Any Queries? 
 Link to Facebook Group: 
https://www.facebook.com/groups/introtopython.iccbs/ 
 Email: 
farjad_bullet@rocketmail.com

More Related Content

What's hot (19)

PDF
Python-01| Fundamentals
Mohd Sajjad
 
PPTX
Chapter 10 data handling
Praveen M Jigajinni
 
PPSX
Programming with Python
Rasan Samarasinghe
 
PPTX
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
PDF
Python revision tour II
Mr. Vikram Singh Slathia
 
PDF
Lesson 03 python statement, indentation and comments
Nilimesh Halder
 
PPTX
Introduction to Python programming Language
MansiSuthar3
 
PDF
Python cheat-sheet
srinivasanr281952
 
PDF
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
PPT
Introduction to Python
amiable_indian
 
PDF
Python Data Types
athithanvijay
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PDF
Data types in python
Learnbay Datascience
 
PPTX
Fundamentals of Python Programming
Kamal Acharya
 
PPTX
Intro to Python Programming Language
Dipankar Achinta
 
PPTX
Introduction to Python Part-1
Devashish Kumar
 
PPTX
Values and Data types in python
Jothi Thilaga P
 
PPTX
Python basics
Manisha Gholve
 
Python-01| Fundamentals
Mohd Sajjad
 
Chapter 10 data handling
Praveen M Jigajinni
 
Programming with Python
Rasan Samarasinghe
 
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
Python revision tour II
Mr. Vikram Singh Slathia
 
Lesson 03 python statement, indentation and comments
Nilimesh Halder
 
Introduction to Python programming Language
MansiSuthar3
 
Python cheat-sheet
srinivasanr281952
 
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
Introduction to Python
amiable_indian
 
Python Data Types
athithanvijay
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
Data types in python
Learnbay Datascience
 
Fundamentals of Python Programming
Kamal Acharya
 
Intro to Python Programming Language
Dipankar Achinta
 
Introduction to Python Part-1
Devashish Kumar
 
Values and Data types in python
Jothi Thilaga P
 
Python basics
Manisha Gholve
 

Viewers also liked (20)

PPT
Substituting HDF5 tools with Python/H5py scripts
The HDF-EOS Tools and Information Center
 
PDF
Logic Over Language
Purple, Rock, Scissors
 
PDF
Python and HDF5: Overview
andrewcollette
 
PPTX
Introduction To Programming with Python-5
Syed Farjad Zia Zaidi
 
PDF
Introduction to Databases
Syed Farjad Zia Zaidi
 
PDF
An Introduction to Interactive Programming in Python 2013
Syed Farjad Zia Zaidi
 
PDF
Logic: Language and Information 1
Syed Farjad Zia Zaidi
 
PDF
Introduction to UBI
Roy Lee
 
PPT
Python 4 Arc
absvis
 
PPT
The Python Programming Language and HDF5: H5Py
The HDF-EOS Tools and Information Center
 
PPTX
Clase 2 estatica
Gerald Moreira Ramírez
 
PPT
Using HDF5 and Python: The H5py module
The HDF-EOS Tools and Information Center
 
PPTX
Python programming - Everyday(ish) Examples
Ashish Sharma
 
PDF
Lets learn Python !
Kiran Gangadharan
 
PPTX
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
PPTX
Cyberoam Firewall Presentation
Manoj Kumar Mishra
 
PDF
introduction to python
Sardar Alam
 
PDF
流程語法與函式
Justin Lin
 
PDF
進階主題
Justin Lin
 
Substituting HDF5 tools with Python/H5py scripts
The HDF-EOS Tools and Information Center
 
Logic Over Language
Purple, Rock, Scissors
 
Python and HDF5: Overview
andrewcollette
 
Introduction To Programming with Python-5
Syed Farjad Zia Zaidi
 
Introduction to Databases
Syed Farjad Zia Zaidi
 
An Introduction to Interactive Programming in Python 2013
Syed Farjad Zia Zaidi
 
Logic: Language and Information 1
Syed Farjad Zia Zaidi
 
Introduction to UBI
Roy Lee
 
Python 4 Arc
absvis
 
The Python Programming Language and HDF5: H5Py
The HDF-EOS Tools and Information Center
 
Clase 2 estatica
Gerald Moreira Ramírez
 
Using HDF5 and Python: The H5py module
The HDF-EOS Tools and Information Center
 
Python programming - Everyday(ish) Examples
Ashish Sharma
 
Lets learn Python !
Kiran Gangadharan
 
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Cyberoam Firewall Presentation
Manoj Kumar Mishra
 
introduction to python
Sardar Alam
 
流程語法與函式
Justin Lin
 
進階主題
Justin Lin
 
Ad

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

PPTX
Python Datatypes by SujithKumar
Sujith Kumar
 
PPTX
PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT
factsandknowledge94
 
PPTX
Python 3.pptx
HarishParthasarathy4
 
PPTX
Chapter - 2.pptx
MikialeTesfamariam
 
PDF
Python Strings Methods
Mr Examples
 
PPT
python1.ppt
arivukarasi2
 
DOCX
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
faithxdunce63732
 
PDF
ppt notes python language operators and data
SukhpreetSingh519414
 
PPTX
trisha comp ppt.pptx
Tapaswini14
 
PPTX
Basic data types in python
sunilchute1
 
PDF
Python Interview Questions PDF By ScholarHat.pdf
Scholarhat
 
PPT
Data types usually used in python for coding
PriyankaRajaboina
 
PPT
02python.ppt
ssuser492e7f
 
PPT
02python.ppt
rehanafarheenece
 
PPTX
Introduction on basic python and it's application
sriram2110
 
PPTX
manish python.pptx
ssuser92d141
 
PPTX
ecFDkQifGYWkHLXQ395.pptxbbbbngvbngrrghxcvvb
JayPatil347597
 
PPTX
11 Introduction to lists.pptx
ssuser8e50d8
 
PPTX
PRESENTATION ON STRING, LISTS AND TUPLES IN PYTHON.pptx
kirtisharma7537
 
PPT
Python Basics
MobeenAhmed25
 
Python Datatypes by SujithKumar
Sujith Kumar
 
PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT
factsandknowledge94
 
Python 3.pptx
HarishParthasarathy4
 
Chapter - 2.pptx
MikialeTesfamariam
 
Python Strings Methods
Mr Examples
 
python1.ppt
arivukarasi2
 
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
faithxdunce63732
 
ppt notes python language operators and data
SukhpreetSingh519414
 
trisha comp ppt.pptx
Tapaswini14
 
Basic data types in python
sunilchute1
 
Python Interview Questions PDF By ScholarHat.pdf
Scholarhat
 
Data types usually used in python for coding
PriyankaRajaboina
 
02python.ppt
ssuser492e7f
 
02python.ppt
rehanafarheenece
 
Introduction on basic python and it's application
sriram2110
 
manish python.pptx
ssuser92d141
 
ecFDkQifGYWkHLXQ395.pptxbbbbngvbngrrghxcvvb
JayPatil347597
 
11 Introduction to lists.pptx
ssuser8e50d8
 
PRESENTATION ON STRING, LISTS AND TUPLES IN PYTHON.pptx
kirtisharma7537
 
Python Basics
MobeenAhmed25
 
Ad

More from Syed Farjad Zia Zaidi (20)

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

Recently uploaded (20)

PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Import Data Form Excel to Tally Services
Tally xperts
 

Introduction To Programming with Python-3

  • 1. Introduction to Programming with Python – Class 3 SYED FARJAD ZIA ZAIDI
  • 2. Class Objectives Class Objective Understanding Strings and some useful string operations. Write few simple programs that use string functions and lists.
  • 3. Class Material •Chapter 6, 8 - Python for Informatics: Exploring Information Reading
  • 4. Strings  Strings are amongst the most popular types in Python. We can create them simply by enclosing characters in quotes. Python treats single quotes the same as double quotes.  Creating strings is as simple as assigning a value to a variable. For example: message = “Hello World”
  • 5. Introduction to Indexing  Strings can be divided into substrings using indexing.  To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring, this is called Indexing. Following is a simple example: message = 'Hello World!' messageTwo = "Python Programming" print "var1[0]: ", message[0] print "var2[1:5]: ", messageTwo[1:5]
  • 6. String Concatenation  String concatenation is a process in which two strings are merged together. Concatenation is very simple and uses the operator ‘+’ to concatenate. For Example: message = “Hello” messageTwo = “ “ messageThree = “World” print message + messageTwo + messageThree
  • 7. Escape Characters  Following table is a list of commonly used escape or non-printable characters that can be represented with backslash notation. An escape character gets interpreted; in a single quoted as well as double quoted strings. Backslash Notation Description n New Line t Space s Tab
  • 8. String Special Operators + •Concatenation - Adds values on either side of the operator * •Repetition - Creates new strings, concatenating multiple copies of the same string
  • 9. Python Comparison Operators [] • Slice - Gives the character from the given index [ : ] •Range Slice - Gives the characters from the given range
  • 10. Python Comparison Operators in • Membership - Returns true if a character exists in the given string not in • Membership - Returns true if a character does not exist in the given string
  • 11. Python Triple Quotes  Python's triple quotes comes to the rescue by allowing strings to span multiple lines, including verbatim NEWLINEs, TABs, and any other special characters.
  • 12. String Functions: Method Description capitalize() Capitalizes first letter of string count(str, beg=0, end=len(string)) Counts how many times str occurs in string or in a substring of string if starting index beg and ending index end are given find(str, beg=0, end=len(string)) Determine if str occurs in string or in a substring of string if starting index beg and ending index end are given returns index if found and -1 otherwise index(str, beg=0, end=len(string)) Same as find(), but raises an error if str not found len(string) Returns the length of the string
  • 13. String Functions:  Go to the following link for more string functions: http://www.tutorialspoint.com/python/python_strings.htm  You can also find string functions by writing the following in the python IDLE help(str)
  • 14. Exercise 1  Write code using find() and string slicing to extract the number at the end of the line below. Convert the extracted value to a floating point number and print it out. text = "X-DSPAM-Confidence: 0.8475";
  • 15. Exercise 2  Given a string and a non-negative int n, return a larger string that is n copies of the original string. string_times('Hi', 2) → 'HiHi' string_times('Hi', 3) → 'HiHiHi' string_times('Hi', 1) → 'Hi'
  • 16. Exercise 3  Given a string, return a string where for every char in the original, there are two chars. double_char('The') → 'TThhee' double_char('AAbb') → 'AAAAbbbb' double_char('Hi-There') → 'HHii--TThheerree'
  • 17. Any Queries?  Link to Facebook Group: https://www.facebook.com/groups/introtopython.iccbs/  Email: [email protected]