SlideShare a Scribd company logo
1 of 6
String in Python
Python String
 Strings in python are surrounded by either single quotation marks, or double
quotation marks.
 'hello' is the same as "hello".
 Ex print("Hello")
 Output: Hello
 Assign string to a variables
 For ex:
 A=“hello”
 Print(a)
 Output:
 Hello
Multiline Strings
 You can assign a multiline string to a variable by using three quotes
 For ex.
 A=“”” Essay are short pieces of writing with a focus on a single subject. It starts with
the introduction of the subject, followed by a middle or body in which the author
gives his argument as per his understanding of the subject followed by a conclusion
paragraph that summarises the findings of the essay.”””
 Print(a)
 In single quotes:
 For ex.
 a=‘’’Essay are short pieces of writing with a focus on a single subject. It starts with the
introduction of the subject, followed by a middle or body in which the author gives his
argument as per his understanding of the subject followed by a conclusion paragraph
that summarises the findings of the essay.’’’
 Print(a)
Strings as array
 Square brackets can be used to access elements of the string.
 For ex.
 A=“hello world”
 Print(a[1])
 Output:
 e
 Slicing string
 You can return a range of characters by using the slice syntax.
 Specify the start index and the end index,
 separated by a colon,
 to return a part of the string.
 For ex.
 b = "Hello, World!"
print(b[2:5])
 Output:
 llo
 Modify Strings
 Upper Case for ex. a=“hello world” print(a.upper())
 Lower Case for ex. A=“hello world” print(a.lower())
 Remove Whitespace for ex. A=“hello world” print(a.strip())
 Replace String for ex. A=“hello world” print(a.replace())
 String Concatenation
 For ex.
 a = "Hello"
b = "World"
c = a + b
print(c)
String in python

More Related Content

Similar to String in python

Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
shailaja30
 
String & its application
String & its applicationString & its application
String & its application
Tech_MX
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
Frankie Jones
 

Similar to String in python (20)

String (Computer programming and utilization)
String (Computer programming and utilization)String (Computer programming and utilization)
String (Computer programming and utilization)
 
Python data handling
Python data handlingPython data handling
Python data handling
 
String in c
String in cString in c
String in c
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
 
Python ppt
Python pptPython ppt
Python ppt
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
C string
C stringC string
C string
 
string in C
string in Cstring in C
string in C
 
String & its application
String & its applicationString & its application
String & its application
 
Strings CPU GTU
Strings CPU GTUStrings CPU GTU
Strings CPU GTU
 
String Methods and Files
String Methods and FilesString Methods and Files
String Methods and Files
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
14 ruby strings
14 ruby strings14 ruby strings
14 ruby strings
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
 
07slide
07slide07slide
07slide
 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

String in python

  • 2. Python String  Strings in python are surrounded by either single quotation marks, or double quotation marks.  'hello' is the same as "hello".  Ex print("Hello")  Output: Hello  Assign string to a variables  For ex:  A=“hello”  Print(a)  Output:  Hello
  • 3. Multiline Strings  You can assign a multiline string to a variable by using three quotes  For ex.  A=“”” Essay are short pieces of writing with a focus on a single subject. It starts with the introduction of the subject, followed by a middle or body in which the author gives his argument as per his understanding of the subject followed by a conclusion paragraph that summarises the findings of the essay.”””  Print(a)  In single quotes:  For ex.  a=‘’’Essay are short pieces of writing with a focus on a single subject. It starts with the introduction of the subject, followed by a middle or body in which the author gives his argument as per his understanding of the subject followed by a conclusion paragraph that summarises the findings of the essay.’’’  Print(a)
  • 4. Strings as array  Square brackets can be used to access elements of the string.  For ex.  A=“hello world”  Print(a[1])  Output:  e  Slicing string  You can return a range of characters by using the slice syntax.  Specify the start index and the end index,  separated by a colon,  to return a part of the string.
  • 5.  For ex.  b = "Hello, World!" print(b[2:5])  Output:  llo  Modify Strings  Upper Case for ex. a=“hello world” print(a.upper())  Lower Case for ex. A=“hello world” print(a.lower())  Remove Whitespace for ex. A=“hello world” print(a.strip())  Replace String for ex. A=“hello world” print(a.replace())  String Concatenation  For ex.  a = "Hello" b = "World" c = a + b print(c)