SlideShare a Scribd company logo
STARTING OUT WITH
Python
Python
Working with Sequences: Strings
1-2
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-2
8.1 Sequences
Concept:
A sequence is an object that holds
multiple items of data, stored one after
the other. You can perform operations
on a sequence, to examine and
manipulate the items stored in it.
1-3
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-3
8.2 Working with Strings
Concept:
Python provides several ways to access
the individual characters in a string.
Strings also have methods that allow
you to perform operations on them.
1-4
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-4
8.2 Working with Strings
Accessing the Individual Characters in a String
Iterating Over a String with the for Loop
Program 8-1
(count_Ts.py)
for variable in string:
statement
statement
etc.
Eg:
name = 'Juliet'
for ch in name:
print(ch)
1-5
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-5
8.2 Working with Strings
Accessing the Individual Characters in a String
Indexing
my_string = ‘Roses are red’
print my_string[0], my_string[6], my_string[10]
print my_string[-1], my_string[-2], my_string[-3]
Figure 8-2 String indexes
1-6
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-6
8.2 Working with Strings
B o s t o n
     
0 1 2 3 4 5
1-7
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-7
8.2 Working with Strings
B o s t o n
     
0 1 2 3 4 5
1-8
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-8
8.2 Working with Strings
Strings Are Immutable
Program 8-2 (concatenate.py)
Figure 8-4 The string
'Carmen' assigned to name
Figure 8-5 The string
'Carmen Brown' assigned
to name
letters = 'abc'
letters += 'def‘ O/p:abcdef
letters = letters + 'def'
1-9
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-9
8.2 Working with Strings
Strings Are Immutable
B i l l
   
0 1 2 3
1-10
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-10
8.2 Working with Strings
String Slicing
1-11
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-11
8.2 Working with Strings
String Slicing
P a t t y L y n n S m i t h
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-16 - 15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 - 2
-1
1-12
M.Trupthi, Assistant Professor, Dept. of IT, CBIT
8-12
8.2 Working with Strings
String Slicing
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
No te: Invalid indexes do not cause slicing expressions to
raise an exception. Pg 366
1-13
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-13
8.2 Working with Strings
Testing Strings with in and not in
1-14
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-14
8.2 Working with Strings
String Methods
Table 8-1 Some string testing methods
stringvar.method(arguments)
general format
1-15
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-15
8.2 Working with Strings
String Methods
Table 8-2 String Modification Methods
1-16
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-16
8.2 Working with Strings
The Repetition Operator … *
Program 8-8 (repetition_operator.py)
string_to_copy * n
my_string = 'w' * 5
print('Hello' * 5)
1-17
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-17
8.3 Lists
Program 8-26
(string_split.py)
1-18
M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-18
8.3 Lists
Program 8-27
(split_date.py)
Program Output
Month: 11
Day: 26
Year: 2014

More Related Content

Similar to Strings_Unit 3 .ppt (20)

PDF
Python Lecture Slides topic strings handling
MuhammadIfitikhar
 
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
PDF
Python strings
Aswini Dharmaraj
 
PPTX
string manipulation in python ppt for grade 11 cbse
KrithikaTM
 
PPTX
Lexture about strings, all examples and theoretical part is included
abzalbekulasbekov
 
PDF
Python data handling
Prof. Dr. K. Adisesha
 
PPT
Chapter05.ppt
afsheenfaiq2
 
PPTX
Engineering string(681) concept ppt.pptx
ChandrashekarReddy98
 
PPTX
Python Programming | JNTUA | UNIT 3 | Strings |
FabMinds
 
PPTX
Python String Revisited.pptx
Chandrapriya Jayabal
 
PPTX
06-Strings.pptx
RaviAr5
 
PPTX
Introduction To Programming with Python-3
Syed Farjad Zia Zaidi
 
PDF
Python Programming Strings
Sreedhar Chowdam
 
PPTX
Strings.pptx
Yagna15
 
PDF
Python- strings
Krishna Nanda
 
PPTX
DATA TYPES IN PYTHON jesjdjdjkdkkdk.pptx
rajvishnuf9
 
PPTX
Python Strings and its Featues Explained in Detail .pptx
parmg0960
 
PPTX
Python Strings Basics with Common Methods.pptx
fzafar1
 
PPTX
presentation on python string manipulation
yanshikasain13
 
PDF
Strings in Python
Vikram Nandini
 
Python Lecture Slides topic strings handling
MuhammadIfitikhar
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Python strings
Aswini Dharmaraj
 
string manipulation in python ppt for grade 11 cbse
KrithikaTM
 
Lexture about strings, all examples and theoretical part is included
abzalbekulasbekov
 
Python data handling
Prof. Dr. K. Adisesha
 
Chapter05.ppt
afsheenfaiq2
 
Engineering string(681) concept ppt.pptx
ChandrashekarReddy98
 
Python Programming | JNTUA | UNIT 3 | Strings |
FabMinds
 
Python String Revisited.pptx
Chandrapriya Jayabal
 
06-Strings.pptx
RaviAr5
 
Introduction To Programming with Python-3
Syed Farjad Zia Zaidi
 
Python Programming Strings
Sreedhar Chowdam
 
Strings.pptx
Yagna15
 
Python- strings
Krishna Nanda
 
DATA TYPES IN PYTHON jesjdjdjkdkkdk.pptx
rajvishnuf9
 
Python Strings and its Featues Explained in Detail .pptx
parmg0960
 
Python Strings Basics with Common Methods.pptx
fzafar1
 
presentation on python string manipulation
yanshikasain13
 
Strings in Python
Vikram Nandini
 

Recently uploaded (20)

PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PDF
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Ad

Strings_Unit 3 .ppt

  • 1. STARTING OUT WITH Python Python Working with Sequences: Strings
  • 2. 1-2 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-2 8.1 Sequences Concept: A sequence is an object that holds multiple items of data, stored one after the other. You can perform operations on a sequence, to examine and manipulate the items stored in it.
  • 3. 1-3 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-3 8.2 Working with Strings Concept: Python provides several ways to access the individual characters in a string. Strings also have methods that allow you to perform operations on them.
  • 4. 1-4 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-4 8.2 Working with Strings Accessing the Individual Characters in a String Iterating Over a String with the for Loop Program 8-1 (count_Ts.py) for variable in string: statement statement etc. Eg: name = 'Juliet' for ch in name: print(ch)
  • 5. 1-5 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-5 8.2 Working with Strings Accessing the Individual Characters in a String Indexing my_string = ‘Roses are red’ print my_string[0], my_string[6], my_string[10] print my_string[-1], my_string[-2], my_string[-3] Figure 8-2 String indexes
  • 6. 1-6 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-6 8.2 Working with Strings B o s t o n       0 1 2 3 4 5
  • 7. 1-7 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-7 8.2 Working with Strings B o s t o n       0 1 2 3 4 5
  • 8. 1-8 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-8 8.2 Working with Strings Strings Are Immutable Program 8-2 (concatenate.py) Figure 8-4 The string 'Carmen' assigned to name Figure 8-5 The string 'Carmen Brown' assigned to name letters = 'abc' letters += 'def‘ O/p:abcdef letters = letters + 'def'
  • 9. 1-9 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-9 8.2 Working with Strings Strings Are Immutable B i l l     0 1 2 3
  • 10. 1-10 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-10 8.2 Working with Strings String Slicing
  • 11. 1-11 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-11 8.2 Working with Strings String Slicing P a t t y L y n n S m i t h 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -16 - 15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 - 2 -1
  • 12. 1-12 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-12 8.2 Working with Strings String Slicing ABCDEFGHIJKLMNOPQRSTUVWXYZ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 No te: Invalid indexes do not cause slicing expressions to raise an exception. Pg 366
  • 13. 1-13 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-13 8.2 Working with Strings Testing Strings with in and not in
  • 14. 1-14 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-14 8.2 Working with Strings String Methods Table 8-1 Some string testing methods stringvar.method(arguments) general format
  • 15. 1-15 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-15 8.2 Working with Strings String Methods Table 8-2 String Modification Methods
  • 16. 1-16 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-16 8.2 Working with Strings The Repetition Operator … * Program 8-8 (repetition_operator.py) string_to_copy * n my_string = 'w' * 5 print('Hello' * 5)
  • 17. 1-17 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-17 8.3 Lists Program 8-26 (string_split.py)
  • 18. 1-18 M.Trupthi, Assistant Professor, Dept. of IT, CBIT 8-18 8.3 Lists Program 8-27 (split_date.py) Program Output Month: 11 Day: 26 Year: 2014