SlideShare uma empresa Scribd logo
1 de 11
M Vishnuvardhan
String
String is basically represents sequence of characters. Technically string is a
sequence of Unicode characters in Python. Strings are written in single or double
quotes. Strings in Python are immutable i.e., modifying the string is not possible
Eg: name='Python’ or name= "Python".
Python allows to create multi line strings using ‘’’ or “””
Eg: msg = """ Python is a Object oriented
Language ""“
: msg = ‘’’ Python is a Object oriented
Language ‘’’
M Vishnuvardhan
Accessing chars in String
Individual characters of a string can be accessed using indexing. Index is a
integer number representing the position of character in the string it starts from
0 and ends at n-1 (n-length)
Eg: name= "Python".
print(name[0]) #returns P
print(name[2]) #returns t
print(name[7]) # index error occurs
Note: Python allows negative indexing on strings. Negative index starts
at -1 and go p to –n.
print(name[-1)) #prints n
M Vishnuvardhan
String – Slicing
Slicing operator (:) is used to get range of indexes. When specifying a range, the
return value will be a new string with the specified items.
Syntax stringName [ start : end ] # start is inclusive and end is exclusive
Eg: name= "Programming"
name[2:5] # returns ogr
If start is skipped then returns items from beginning, If end is skipped then
returns items till end .Slicing allows negative indexing also
name[-6:-3] # returns amm
-11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
P r o g r a m m i n g
0 1 2 3 4 5 6 7 8 9 10
M Vishnuvardhan
String – Advanced Slicing
Syntax stringName [ start : end: step ]
# start is inclusive and end is exclusive and step is increment
Eg: name= "Programming«
[low:high:+ve] – normal order
name[2:10:2] # returns ormi
[high:low:-ve] – reverse order
name[10:2:-1] # returns gnimmarg
name[::1] # returns Programming
name[::-1] # returns gnimmargorP
-11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
P r o g r a m m i n g
0 1 2 3 4 5 6 7 8 9 10
M Vishnuvardhan
String – Basic Operations
Python Expression Results Description
len(“Python”) 6 Length
“Python” + “Program” “PythonProgram” Concatenation
Py* 4 “PyPyPy” Repetition
y in “Python” True Membership
for x in “Python”:
print x
P y t h o n Iteration
M Vishnuvardhan
String methods
Method Description
count() Returns the number of times a specified value occurs in a string
find()
Searches the string for a specified value and returns the position of
where it was found
format() Formats specified values in a string
index()
Searches the string for a specified value and returns the position of
where it was found
isalnum() Returns True if all characters in the string are alphanumeric
isalpha() Returns True if all characters in the string are in the alphabet
isdecimal() Returns True if all characters in the string are decimals
isdigit() Returns True if all characters in the string are digits
islower() Returns True if all characters in the string are lower case
M Vishnuvardhan
String methods
Method Description
isnumeric() Returns True if all characters in the string are numeric
isupper() Returns True if all characters in the string are upper case
join() Converts the elements of an iterable into a string
lower() Converts a string into lower case
replace()
Returns a string where a specified value is replaced with a specified
value
split() Splits the string at the specified separator, and returns a list
strip() Returns a trimmed version of the string
title() Converts the first character of each word to upper case
upper() Converts a string into upper case
M Vishnuvardhan
String Formatting
format() method allows you to format selected parts of a string. It takes the
passed arguments, formats them, and places them in the string where the
placeholders {} are:
Syntax: string.format(value1, value2...)
The placeholders can be identified using named indexes {price}, numbered
indexes {0}, or even empty placeholders {}.
Eg:
txt1 = "Python {name}, is {ver}".format(name = "Language", ver = 3.10)
txt2 = "Python {0}, is {1}".format("Language",3.10)
txt3 = "Python {}, is {}".format("Language",3.10)
M Vishnuvardhan
String Escape Sequences
Code Result
' Single Quote
 Backslash
n New Line
r Carriage Return
t Tab
b Backspace
f Form Feed
ooo Octal value
xhh Hex value
M Vishnuvardhan

Mais conteúdo relacionado

Semelhante a Python Strings.pptx

STRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptxSTRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptxTinku91
 
Introduction to python programming ( part-3 )
Introduction to python programming ( part-3 )Introduction to python programming ( part-3 )
Introduction to python programming ( part-3 )Ziyauddin Shaik
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings MethodsMr Examples
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfomprakashmeena48
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiMohamed Abdallah
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptxPadreBhoj
 
Chapter 11 Strings.pptx
Chapter 11 Strings.pptxChapter 11 Strings.pptx
Chapter 11 Strings.pptxafsheenfaiq2
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumarSujith Kumar
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressionsKrishna Nanda
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it outrajatryadav22
 
Detailed description of Strings in Python
Detailed description of Strings in PythonDetailed description of Strings in Python
Detailed description of Strings in PythonKeerthiraja11
 

Semelhante a Python Strings.pptx (20)

Python data handling
Python data handlingPython data handling
Python data handling
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
python_strings.pdf
python_strings.pdfpython_strings.pdf
python_strings.pdf
 
STRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptxSTRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptx
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
String notes
String notesString notes
String notes
 
Introduction to python programming ( part-3 )
Introduction to python programming ( part-3 )Introduction to python programming ( part-3 )
Introduction to python programming ( part-3 )
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings Methods
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdf
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptx
 
strings11.pdf
strings11.pdfstrings11.pdf
strings11.pdf
 
Chapter 11 Strings.pptx
Chapter 11 Strings.pptxChapter 11 Strings.pptx
Chapter 11 Strings.pptx
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
 
unit 1.docx
unit 1.docxunit 1.docx
unit 1.docx
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
 
Detailed description of Strings in Python
Detailed description of Strings in PythonDetailed description of Strings in Python
Detailed description of Strings in Python
 

Mais de M Vishnuvardhan Reddy (20)

Python Sets_Dictionary.pptx
Python Sets_Dictionary.pptxPython Sets_Dictionary.pptx
Python Sets_Dictionary.pptx
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
 
Python Control Structures.pptx
Python Control Structures.pptxPython Control Structures.pptx
Python Control Structures.pptx
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
 
Python Operators.pptx
Python Operators.pptxPython Operators.pptx
Python Operators.pptx
 
Python Datatypes.pptx
Python Datatypes.pptxPython Datatypes.pptx
Python Datatypes.pptx
 
DataScience.pptx
DataScience.pptxDataScience.pptx
DataScience.pptx
 
Html forms
Html formsHtml forms
Html forms
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Scanner class
Scanner classScanner class
Scanner class
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Java intro
Java introJava intro
Java intro
 
Java applets
Java appletsJava applets
Java applets
 
Exception handling
Exception handling Exception handling
Exception handling
 
Control structures
Control structuresControl structures
Control structures
 
Constructors
ConstructorsConstructors
Constructors
 
Classes&objects
Classes&objectsClasses&objects
Classes&objects
 
Shell sort
Shell sortShell sort
Shell sort
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Python Strings.pptx

  • 1.
  • 2. M Vishnuvardhan String String is basically represents sequence of characters. Technically string is a sequence of Unicode characters in Python. Strings are written in single or double quotes. Strings in Python are immutable i.e., modifying the string is not possible Eg: name='Python’ or name= "Python". Python allows to create multi line strings using ‘’’ or “”” Eg: msg = """ Python is a Object oriented Language ""“ : msg = ‘’’ Python is a Object oriented Language ‘’’
  • 3. M Vishnuvardhan Accessing chars in String Individual characters of a string can be accessed using indexing. Index is a integer number representing the position of character in the string it starts from 0 and ends at n-1 (n-length) Eg: name= "Python". print(name[0]) #returns P print(name[2]) #returns t print(name[7]) # index error occurs Note: Python allows negative indexing on strings. Negative index starts at -1 and go p to –n. print(name[-1)) #prints n
  • 4. M Vishnuvardhan String – Slicing Slicing operator (:) is used to get range of indexes. When specifying a range, the return value will be a new string with the specified items. Syntax stringName [ start : end ] # start is inclusive and end is exclusive Eg: name= "Programming" name[2:5] # returns ogr If start is skipped then returns items from beginning, If end is skipped then returns items till end .Slicing allows negative indexing also name[-6:-3] # returns amm -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 P r o g r a m m i n g 0 1 2 3 4 5 6 7 8 9 10
  • 5. M Vishnuvardhan String – Advanced Slicing Syntax stringName [ start : end: step ] # start is inclusive and end is exclusive and step is increment Eg: name= "Programming« [low:high:+ve] – normal order name[2:10:2] # returns ormi [high:low:-ve] – reverse order name[10:2:-1] # returns gnimmarg name[::1] # returns Programming name[::-1] # returns gnimmargorP -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 P r o g r a m m i n g 0 1 2 3 4 5 6 7 8 9 10
  • 6. M Vishnuvardhan String – Basic Operations Python Expression Results Description len(“Python”) 6 Length “Python” + “Program” “PythonProgram” Concatenation Py* 4 “PyPyPy” Repetition y in “Python” True Membership for x in “Python”: print x P y t h o n Iteration
  • 7. M Vishnuvardhan String methods Method Description count() Returns the number of times a specified value occurs in a string find() Searches the string for a specified value and returns the position of where it was found format() Formats specified values in a string index() Searches the string for a specified value and returns the position of where it was found isalnum() Returns True if all characters in the string are alphanumeric isalpha() Returns True if all characters in the string are in the alphabet isdecimal() Returns True if all characters in the string are decimals isdigit() Returns True if all characters in the string are digits islower() Returns True if all characters in the string are lower case
  • 8. M Vishnuvardhan String methods Method Description isnumeric() Returns True if all characters in the string are numeric isupper() Returns True if all characters in the string are upper case join() Converts the elements of an iterable into a string lower() Converts a string into lower case replace() Returns a string where a specified value is replaced with a specified value split() Splits the string at the specified separator, and returns a list strip() Returns a trimmed version of the string title() Converts the first character of each word to upper case upper() Converts a string into upper case
  • 9. M Vishnuvardhan String Formatting format() method allows you to format selected parts of a string. It takes the passed arguments, formats them, and places them in the string where the placeholders {} are: Syntax: string.format(value1, value2...) The placeholders can be identified using named indexes {price}, numbered indexes {0}, or even empty placeholders {}. Eg: txt1 = "Python {name}, is {ver}".format(name = "Language", ver = 3.10) txt2 = "Python {0}, is {1}".format("Language",3.10) txt3 = "Python {}, is {}".format("Language",3.10)
  • 10. M Vishnuvardhan String Escape Sequences Code Result ' Single Quote Backslash n New Line r Carriage Return t Tab b Backspace f Form Feed ooo Octal value xhh Hex value