SlideShare a Scribd company logo
3
Most read
4
Most read
7
Most read
19 Apr 2022: Unit 3: Strings
PYTHON PROGRAMMING
B.Tech IV Sem CSE A
Python Programming Strings
Today’s Topics
str class,
string inbuilt functions,
index[],
traversing string: for, while,
immutable strings,
string operators,
string operations
str class
 Strings are objects of the str class. We can create a string using
the constructor of str class.
The syntax of str() is:
 str(object, encoding='utf-8', errors='strict')
 object - The object whose string representation is to be
returned. If not provided, returns the empty string
 encoding - Encoding of the given object. Defaults of UTF-8
when not provided.
 errors - Response when decoding fails. Defaults to 'strict'.
str examples
name=str("Sreedhar")
age=str(24)
print(name)
print(age)
branch="computerscienceandengineering"
print(branch)
print(len(branch))
print(min(branch))
print(max(branch))
print(branch.center(40,'#'))
print(branch.find('science'))
Sreedhar
24
computerscienceandengineering
29
a
u
#####computerscienceandengineering######
8
print(branch.find('science',8,18))
print(branch.find('m',0,10))
print(branch.rfind('engine'))
print(branch.swapcase())
print(branch.startswith('science'))
print(branch.startswith('computer'))
print(branch)
print(branch.capitalize())
print(branch.upper())
8
2
18
COMPUTERSCIENCEANDENGINEERING
False
True
computerscienceandengineering
Computerscienceandengineering
COMPUTERSCIENCEANDENGINEERING
branches = 'cse, cst, csbs, ece'
branches.split()
branches.split(",") ['cse', ' cst', ' csbs', ' ece']
text = 'Binary Search'
print(text.rjust(20),"is a classic recursive algorithm")
text = 'Quick Search'
print(text.ljust(10),"is a classic recursive algorithm")
Binary Search is a classic recursive algorithm
Quick Search is a classic recursive algorithm
BASIC INBUILT PYTHON FUNCTIONS FOR
STRING
 len(a) #Return length i.e. number of characters in string a
 min(a) #Return smallest character present in a string
 max(a) #Return largest character present in a string
Index[ ] operator
 The indexing operator (Python uses square brackets to
enclose the index) selects a single character from a string,
characters are accessed by their position or index value.
index[] OPERATOR
a="Welcome to CSE4A students"
b=['Mango','per kg','value','is',204.14]
c=('Apple','per kg','value','is',103.24)
d=a[2]
print(d)
lastchar=a[-1]
print(lastchar)
print(b[2])
print(b[3-6])
print(b[-2])
print(c[0])
print(c[-1])
print(c[2-4])
print(b[7-8])
l
s
value
value
is
Apple
103.24
is
204.14
traversing string: for,while,
branch="Computer Science"
for char in branch:
print(char,end="")
string="Python Programming CSE4A"
j = 0
while j < len(string):
j += 1
print(string[0:j])
immutable strings
 Character sequences fall into two categories, i.e.
mutable and immutable.
 Mutable means changeable and immutable means
unchangeable.
 Strings are immutable sequences of characters.
String operators
branch="Computer Science and engineering"
print(branch[0])
print(branch[:3])
print(branch[2:6])
print(branch[4:])
print(branch[:])
print(branch[::-1])
print(branch[4::-1])
print(branch[0:16:2])
branch+=" !!"
print(branch)
C
Com
mput
uter Science and engineering
Computer Science and engineering
gnireenigne dna ecneicS retupmoC
upmoC
Cmue cec
Computer Science and engineering !!
college="G Pulla Reddy Engineering College"
branch="Computer Science and Engineering"
print(college+branch)
print(branch*2)
a="Engineering" in college
print(a)
b="JNTU" in college
print(b)
c="Maths" not in branch
print(c)
d="Science" not in branch
print(d)
G Pulla Reddy Engineering CollegeComputer Science and Engineering
Computer Science and EngineeringComputer Science and Engineering
True
False
True
False
string operations
 String Comparison
 String .format() Method()
 split() Method
 Testing String
 Searching Substring in a String
 Methods to Convert a String into Another String
 Stripping Unwanted Characters from a String
 Formatting String
branch1="Computer Science and Engineering"
branch2="Computer Science Technology"
print(branch1>branch2)
branch3="Computer Science Technology"
print(branch2==branch3)
print(branch2.split())
print(branch2.isalnum())
print(branch2.isalpha())
print(branch2.isdigit())
print(branch2.islower())
print(branch2.isupper())
print(branch2.isspace())
a="123test"
print(a.isalnum())
print(a.isalpha())
b="45678"
print(b.isdigit())
True
True
['Computer', 'Science', 'Technology']
False
False
False
False
False
False
True
False
True
course="G Pulla Reddy Engineering College"
print(course.endswith("College"))
print(course.startswith("Programming"))
print(course.find("Engineering"))
print(course.count("e"))
a="G Pulla Reddy Engineering Collegenntt"
print(a.rstrip())
True
False
14
5
G Pulla Reddy Engineering College
Ad

Recommended

Python Programming
Python Programming
Sreedhar Chowdam
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
Shivam Mitra
 
Introduction to Python
Introduction to Python
Mohammed Sikander
 
Python Programming
Python Programming
Sreedhar Chowdam
 
Values and Data types in python
Values and Data types in python
Jothi Thilaga P
 
Python programming
Python programming
Prof. Dr. K. Adisesha
 
Strings in Python
Strings in Python
nitamhaske
 
Python-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
Sreedhar Chowdam
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdf
Sreedhar Chowdam
 
Oops presentation
Oops presentation
sushamaGavarskar1
 
Python-03| Data types
Python-03| Data types
Mohd Sajjad
 
Strings in C language
Strings in C language
P M Patil
 
Python Part 1
Python Part 1
Sunil OS
 
List and Dictionary in python
List and Dictionary in python
Sangita Panchal
 
Python dictionary
Python dictionary
Sagar Kumar
 
C programs
C programs
Minu S
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
PriyankaC44
 
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
P3 InfoTech Solutions Pvt. Ltd.
 
Python Modules
Python Modules
Nitin Reddy Katkam
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILE
Dipta Saha
 
Two dimensional array
Two dimensional array
Rajendran
 
Introduction to python
Introduction to python
Yi-Fan Chu
 
Python variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Control statements in c
Control statements in c
Sathish Narayanan
 
String handling
String handling
IyeTech - Pakistan
 
String C Programming
String C Programming
Prionto Abdullah
 
Python strings
Python strings
Aswini Dharmaraj
 
PPS_Unit 4.ppt
PPS_Unit 4.ppt
KundanBhatkar
 

More Related Content

What's hot (20)

Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
Sreedhar Chowdam
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdf
Sreedhar Chowdam
 
Oops presentation
Oops presentation
sushamaGavarskar1
 
Python-03| Data types
Python-03| Data types
Mohd Sajjad
 
Strings in C language
Strings in C language
P M Patil
 
Python Part 1
Python Part 1
Sunil OS
 
List and Dictionary in python
List and Dictionary in python
Sangita Panchal
 
Python dictionary
Python dictionary
Sagar Kumar
 
C programs
C programs
Minu S
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
PriyankaC44
 
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
P3 InfoTech Solutions Pvt. Ltd.
 
Python Modules
Python Modules
Nitin Reddy Katkam
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILE
Dipta Saha
 
Two dimensional array
Two dimensional array
Rajendran
 
Introduction to python
Introduction to python
Yi-Fan Chu
 
Python variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Control statements in c
Control statements in c
Sathish Narayanan
 
String handling
String handling
IyeTech - Pakistan
 
String C Programming
String C Programming
Prionto Abdullah
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
Sreedhar Chowdam
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdf
Sreedhar Chowdam
 
Python-03| Data types
Python-03| Data types
Mohd Sajjad
 
Strings in C language
Strings in C language
P M Patil
 
Python Part 1
Python Part 1
Sunil OS
 
List and Dictionary in python
List and Dictionary in python
Sangita Panchal
 
Python dictionary
Python dictionary
Sagar Kumar
 
C programs
C programs
Minu S
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
PriyankaC44
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILE
Dipta Saha
 
Two dimensional array
Two dimensional array
Rajendran
 
Introduction to python
Introduction to python
Yi-Fan Chu
 
Python variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 

Similar to Python Programming Strings (20)

Python strings
Python strings
Aswini Dharmaraj
 
PPS_Unit 4.ppt
PPS_Unit 4.ppt
KundanBhatkar
 
Python Programming-UNIT-II - Strings.pptx
Python Programming-UNIT-II - Strings.pptx
KavithaDonepudi
 
Engineering string(681) concept ppt.pptx
Engineering string(681) concept ppt.pptx
ChandrashekarReddy98
 
Strings in Python
Strings in Python
International Institute of Information Technology (I²IT)
 
string manipulation in python ppt for grade 11 cbse
string manipulation in python ppt for grade 11 cbse
KrithikaTM
 
Chapter 11 Strings and methods [Autosaved].pptx
Chapter 11 Strings and methods [Autosaved].pptx
geethar79
 
strings11.pdf
strings11.pdf
TARUNKUMAR845504
 
"Strings in Python - Presentation Slide"
"Strings in Python - Presentation Slide"
altacc1921
 
Python- strings
Python- strings
Krishna Nanda
 
Python data handling
Python data handling
Prof. Dr. K. Adisesha
 
Strings brief introduction in python.pdf
Strings brief introduction in python.pdf
TODAYIREAD1
 
Chapter 14 strings
Chapter 14 strings
Praveen M Jigajinni
 
Python programming : Strings
Python programming : Strings
Emertxe Information Technologies Pvt Ltd
 
varthini python .pptx
varthini python .pptx
MJeyavarthini
 
Chapter 11 Strings.pptx
Chapter 11 Strings.pptx
afsheenfaiq2
 
00012.PYTHON - STRING MANIPULATION SLIDES
00012.PYTHON - STRING MANIPULATION SLIDES
PanavGupta3
 
trisha comp ppt.pptx
trisha comp ppt.pptx
Tapaswini14
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Python String Revisited.pptx
Python String Revisited.pptx
Chandrapriya Jayabal
 
Python Programming-UNIT-II - Strings.pptx
Python Programming-UNIT-II - Strings.pptx
KavithaDonepudi
 
Engineering string(681) concept ppt.pptx
Engineering string(681) concept ppt.pptx
ChandrashekarReddy98
 
string manipulation in python ppt for grade 11 cbse
string manipulation in python ppt for grade 11 cbse
KrithikaTM
 
Chapter 11 Strings and methods [Autosaved].pptx
Chapter 11 Strings and methods [Autosaved].pptx
geethar79
 
"Strings in Python - Presentation Slide"
"Strings in Python - Presentation Slide"
altacc1921
 
Strings brief introduction in python.pdf
Strings brief introduction in python.pdf
TODAYIREAD1
 
varthini python .pptx
varthini python .pptx
MJeyavarthini
 
Chapter 11 Strings.pptx
Chapter 11 Strings.pptx
afsheenfaiq2
 
00012.PYTHON - STRING MANIPULATION SLIDES
00012.PYTHON - STRING MANIPULATION SLIDES
PanavGupta3
 
trisha comp ppt.pptx
trisha comp ppt.pptx
Tapaswini14
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Ad

More from Sreedhar Chowdam (20)

DBMS Nested & Sub Queries Set operations
DBMS Nested & Sub Queries Set operations
Sreedhar Chowdam
 
DBMS Notes selection projection aggregate
DBMS Notes selection projection aggregate
Sreedhar Chowdam
 
Database management systems Lecture Notes
Database management systems Lecture Notes
Sreedhar Chowdam
 
Advanced Data Structures & Algorithm Analysi
Advanced Data Structures & Algorithm Analysi
Sreedhar Chowdam
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
Sreedhar Chowdam
 
Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)
Sreedhar Chowdam
 
DCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCP
Sreedhar Chowdam
 
Data Communication and Computer Networks
Data Communication and Computer Networks
Sreedhar Chowdam
 
DCCN Unit 1.pdf
DCCN Unit 1.pdf
Sreedhar Chowdam
 
Data Communication & Computer Networks
Data Communication & Computer Networks
Sreedhar Chowdam
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
Sreedhar Chowdam
 
PPS Arrays Matrix operations
PPS Arrays Matrix operations
Sreedhar Chowdam
 
Programming for Problem Solving
Programming for Problem Solving
Sreedhar Chowdam
 
Big Data Analytics Part2
Big Data Analytics Part2
Sreedhar Chowdam
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
Sreedhar Chowdam
 
C Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
Sreedhar Chowdam
 
Big Data Analytics
Big Data Analytics
Sreedhar Chowdam
 
Data Structures Notes 2021
Data Structures Notes 2021
Sreedhar Chowdam
 
DBMS Nested & Sub Queries Set operations
DBMS Nested & Sub Queries Set operations
Sreedhar Chowdam
 
DBMS Notes selection projection aggregate
DBMS Notes selection projection aggregate
Sreedhar Chowdam
 
Database management systems Lecture Notes
Database management systems Lecture Notes
Sreedhar Chowdam
 
Advanced Data Structures & Algorithm Analysi
Advanced Data Structures & Algorithm Analysi
Sreedhar Chowdam
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
Sreedhar Chowdam
 
Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)
Sreedhar Chowdam
 
DCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCP
Sreedhar Chowdam
 
Data Communication and Computer Networks
Data Communication and Computer Networks
Sreedhar Chowdam
 
Data Communication & Computer Networks
Data Communication & Computer Networks
Sreedhar Chowdam
 
PPS Arrays Matrix operations
PPS Arrays Matrix operations
Sreedhar Chowdam
 
Programming for Problem Solving
Programming for Problem Solving
Sreedhar Chowdam
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
Sreedhar Chowdam
 
C Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
Sreedhar Chowdam
 
Data Structures Notes 2021
Data Structures Notes 2021
Sreedhar Chowdam
 
Ad

Recently uploaded (20)

Solar thermal – Flat plate and concentrating collectors .pptx
Solar thermal – Flat plate and concentrating collectors .pptx
jdaniabraham1
 
Bitumen Emulsion by Dr Sangita Ex CRRI Delhi
Bitumen Emulsion by Dr Sangita Ex CRRI Delhi
grilcodes
 
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
resming1
 
Call For Papers - 17th International Conference on Wireless & Mobile Networks...
Call For Papers - 17th International Conference on Wireless & Mobile Networks...
hosseinihamid192023
 
Complete guidance book of Asp.Net Web API
Complete guidance book of Asp.Net Web API
Shabista Imam
 
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
resming1
 
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
 
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
Solar thermal – Flat plate and concentrating collectors .pptx
Solar thermal – Flat plate and concentrating collectors .pptx
jdaniabraham1
 
Bitumen Emulsion by Dr Sangita Ex CRRI Delhi
Bitumen Emulsion by Dr Sangita Ex CRRI Delhi
grilcodes
 
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
resming1
 
Call For Papers - 17th International Conference on Wireless & Mobile Networks...
Call For Papers - 17th International Conference on Wireless & Mobile Networks...
hosseinihamid192023
 
Complete guidance book of Asp.Net Web API
Complete guidance book of Asp.Net Web API
Shabista Imam
 
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
resming1
 
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
 
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 

Python Programming Strings