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

More Related Content

What's hot (20)

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

Similar to Python Programming Strings (20)

PDF
Python Cheat Sheet
Muthu Vinayagam
 
PDF
vision_academy_classes_Bcs_bca_bba_java part_2 (1).pdf
bhagyashri686896
 
PDF
Vision academy classes_bcs_bca_bba_java part_2
NayanTapare1
 
PPTX
An introduction to matlab
Dr. Andrew Wallace PhD
 
PDF
An overview of Python 2.7
decoupled
 
PDF
A tour of Python
Aleksandar Veselinovic
 
PPTX
Python Cheat Sheet Presentation Learning
Naseer-ul-Hassan Rehman
 
PDF
The Ring programming language version 1.5.3 book - Part 35 of 184
Mahmoud Samir Fayed
 
PPTX
manipulation of Strings+PPT.pptx
ShowribabuKanta
 
PPT
Arrays
Rahul Mahamuni
 
PPTX
Syntax Comparison of Golang with C and Java - Mindbowser
Mindbowser Inc
 
PPTX
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
PDF
STRING LIST TUPLE DICTIONARY FILE.pdf
omprakashmeena48
 
PDF
The Ring programming language version 1.6 book - Part 37 of 189
Mahmoud Samir Fayed
 
PDF
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
PDF
Python cheatsheat.pdf
HimoZZZ
 
PPT
Charcater and Strings.ppt Charcater and Strings.ppt
mulualem37
 
PPTX
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
PDF
talk at Virginia Bioinformatics Institute, December 5, 2013
ericupnorth
 
PPT
sonam Kumari python.ppt
ssuserd64918
 
Python Cheat Sheet
Muthu Vinayagam
 
vision_academy_classes_Bcs_bca_bba_java part_2 (1).pdf
bhagyashri686896
 
Vision academy classes_bcs_bca_bba_java part_2
NayanTapare1
 
An introduction to matlab
Dr. Andrew Wallace PhD
 
An overview of Python 2.7
decoupled
 
A tour of Python
Aleksandar Veselinovic
 
Python Cheat Sheet Presentation Learning
Naseer-ul-Hassan Rehman
 
The Ring programming language version 1.5.3 book - Part 35 of 184
Mahmoud Samir Fayed
 
manipulation of Strings+PPT.pptx
ShowribabuKanta
 
Syntax Comparison of Golang with C and Java - Mindbowser
Mindbowser Inc
 
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
STRING LIST TUPLE DICTIONARY FILE.pdf
omprakashmeena48
 
The Ring programming language version 1.6 book - Part 37 of 189
Mahmoud Samir Fayed
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
Python cheatsheat.pdf
HimoZZZ
 
Charcater and Strings.ppt Charcater and Strings.ppt
mulualem37
 
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
talk at Virginia Bioinformatics Institute, December 5, 2013
ericupnorth
 
sonam Kumari python.ppt
ssuserd64918
 
Ad

More from Sreedhar Chowdam (20)

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

Recently uploaded (20)

PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
Digital water marking system project report
Kamal Acharya
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PDF
Bachelor of information technology syll
SudarsanAssistantPro
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Digital water marking system project report
Kamal Acharya
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
Bachelor of information technology syll
SudarsanAssistantPro
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 

Python Programming Strings