SlideShare a Scribd company logo
String in Python
Presented by - Aryadip Dey
6th Sem, Textile Technology
University roll no. - 11001420029
Govt. College of Engineering & Textile Technology, Serampore
Content
 String- Introduction
 Reading and printing a String
 Accessing individual character
 Repetition
 String slicing
 String concatenation
 Splitting of string
 Split separator
 Conversion of string
String- Introduction
 Strings are a collection of characters which are stored together to
represent arbitrary text inside a python program.
 We can create a string inside a python program by surrounding text
with either single quotes (’), double quotes ("), or a collection of three
of either types of quotes (’’’ or""").
 Python uses Unicode format to represent strings.
 Here are a few examples of how to create a string constant and assign
its value to a variable:
 Name = ‘aryadipdey’
 College = “gcetts”
Reading and printing a String
 Reading and printing a string in python is shown below.
 For example:
 Write a program to read and print a string
print(“Enter your name”)
Name = input()
print(“Hi”,Name,”Lets learn about strings in Python”)
Accessing individual character
 We can access individual characters of string using indexing.
 Indexing allows negative address references to access characters from the back of
the string, e.g. -1 refers to the last character, -2 refers to the second last character
and so on. (See the below figure).
 While accessing an index out of the range will cause an indexerror.
T E X T I L E
0 1 2 3 4 5 6
-7 -6 -5 -4 -3 -2 -1
Repetition
 The asterisk (*), when used between a string and an integer
creates a new string with the old string repeated by the value of
the integer.
 The order of the arguments is not important.
 Example:
 Write a program to repeat a given string
word=“hello”
echo = word*5
print(echo) #output: hellohellohellohellohello
String slicing
 To access a range of characters in the string, method of
slicing is used.
 Slicing in a string is done by using a slicing operator (colon).
 We can access substrings using slicing
 For example:
 Write a program to slice a given string
C= “Whatever it takes”
print(C) #output: Whatever it takes
D=C[5:7]
print(D) #output:ve
E=C[9:11]
print(E) #output: it
String concatenation
 Joining of two or more strings into a single one is called concatenation.
 The + operator does this in python.
 The * operator can be used to repeat the string for a given number of times.
 For example:
 Write a program to join two different string into a single one
firstname = “aryadip” lastname = “dey”
fullname=firstname + lastname
print(fullname) #output: aryadipdey
Splitting of string
 By using split command we can get a list of the words in string.
 For example:
 Write a program to create a list of word from a given string
a= "i am a boy”
print(a) #output: i am a boy
print(type(a)) #output: <class 'str'>
print(len(a)) #output: 10
w= a.split()
print(w) #output: ['i', 'am', 'a', 'boy']
print(type(w)) #output: <class 'list'>
print(len(w)) #output: 4
Split separator
 Default separator is any space(space, newline, tab)
 To specify any other separator, specify it explicitly.
 For Example:
 Write a program to split a string separated with a separator
a= "fibre,yarn,fabric”
print(a) #output: fibre,yarn,fabric
print(type(a)) #output: <class 'str'>
print(len(a)) #output: 17
w= a.split(',’)
print(w) #output: ['fibre', 'yarn', 'fabric']
print(type(w)) #output: <class 'list'>
print(len(w)) #output: 3
Conversion of string
 A string may be present in lower case or upper case. The string in lower case
can be converted into upper case and vice versa using various methods of the
str class.
Conversion of string (Continued)
Reference
 Introduction to Python Programming Course Notes by Phil Spector
 https://www.programiz.com/python-programming/online-compiler/
 https://www.slideshare.net
Different uses of  String in Python.pptx

More Related Content

PDF
Python- strings
PPTX
Python Programming-UNIT-II - Strings.pptx
PPTX
STRINGS IN PYTHON
PDF
strings in python (presentation for DSA)
PPT
PPS_Unit 4.ppt
PDF
Python data handling
PPTX
varthini python .pptx
PPTX
Python Strings and its Featues Explained in Detail .pptx
Python- strings
Python Programming-UNIT-II - Strings.pptx
STRINGS IN PYTHON
strings in python (presentation for DSA)
PPS_Unit 4.ppt
Python data handling
varthini python .pptx
Python Strings and its Featues Explained in Detail .pptx

Similar to Different uses of String in Python.pptx (20)

PPTX
UNIT 4 python.pptx
PPTX
trisha comp ppt.pptx
PDF
ppt notes python language operators and data
PDF
Python strings
PDF
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
PPTX
Python Strings.pptx
PDF
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
PPT
Introduction to Python
PPTX
STRINGS_IN_PYTHON 9-12 (1).pptx
PDF
Strings in Python
PPTX
Strings.pptx
PPTX
ecFDkQifGYWkHLXQ395.pptxbbbbngvbngrrghxcvvb
PPTX
Engineering string(681) concept ppt.pptx
PPTX
Python strings presentation
PPTX
Python Strings.pptx
PPTX
Introduction To Programming with Python-3
PPTX
string manipulation in python ppt for grade 11 cbse
PPTX
stringggg.pptxtujd7ttttttttttttttttttttttttttttttttttt
PPTX
PPTX
Python Strings and strings types with Examples
UNIT 4 python.pptx
trisha comp ppt.pptx
ppt notes python language operators and data
Python strings
Strings3a4esrxdfgcbhjjjjjiiol;lkljiojoii
Python Strings.pptx
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
Introduction to Python
STRINGS_IN_PYTHON 9-12 (1).pptx
Strings in Python
Strings.pptx
ecFDkQifGYWkHLXQ395.pptxbbbbngvbngrrghxcvvb
Engineering string(681) concept ppt.pptx
Python strings presentation
Python Strings.pptx
Introduction To Programming with Python-3
string manipulation in python ppt for grade 11 cbse
stringggg.pptxtujd7ttttttttttttttttttttttttttttttttttt
Python Strings and strings types with Examples
Ad

More from AryadipDey (6)

PPTX
An Introduction to Merchandising.pptx
PPTX
An overview of Indian Constitution.pptx
PPTX
Supply Chain Management in Textile Industry.pptx
PPTX
Basic dye application in textile industry.pptx
PPTX
Accounting concepts and conventions.pptx
PPTX
Different methods used in testing of intelligent fabric.pptx
An Introduction to Merchandising.pptx
An overview of Indian Constitution.pptx
Supply Chain Management in Textile Industry.pptx
Basic dye application in textile industry.pptx
Accounting concepts and conventions.pptx
Different methods used in testing of intelligent fabric.pptx
Ad

Recently uploaded (20)

PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
DOCX
573137875-Attendance-Management-System-original
PPTX
web development for engineering and engineering
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Well-logging-methods_new................
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Digital Logic Computer Design lecture notes
PPTX
Lecture Notes Electrical Wiring System Components
PDF
PPT on Performance Review to get promotions
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
CH1 Production IntroductoryConcepts.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
CYBER-CRIMES AND SECURITY A guide to understanding
573137875-Attendance-Management-System-original
web development for engineering and engineering
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
UNIT 4 Total Quality Management .pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Well-logging-methods_new................
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Digital Logic Computer Design lecture notes
Lecture Notes Electrical Wiring System Components
PPT on Performance Review to get promotions
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Foundation to blockchain - A guide to Blockchain Tech
CH1 Production IntroductoryConcepts.pptx

Different uses of String in Python.pptx

  • 1. String in Python Presented by - Aryadip Dey 6th Sem, Textile Technology University roll no. - 11001420029 Govt. College of Engineering & Textile Technology, Serampore
  • 2. Content  String- Introduction  Reading and printing a String  Accessing individual character  Repetition  String slicing  String concatenation  Splitting of string  Split separator  Conversion of string
  • 3. String- Introduction  Strings are a collection of characters which are stored together to represent arbitrary text inside a python program.  We can create a string inside a python program by surrounding text with either single quotes (’), double quotes ("), or a collection of three of either types of quotes (’’’ or""").  Python uses Unicode format to represent strings.  Here are a few examples of how to create a string constant and assign its value to a variable:  Name = ‘aryadipdey’  College = “gcetts”
  • 4. Reading and printing a String  Reading and printing a string in python is shown below.  For example:  Write a program to read and print a string print(“Enter your name”) Name = input() print(“Hi”,Name,”Lets learn about strings in Python”)
  • 5. Accessing individual character  We can access individual characters of string using indexing.  Indexing allows negative address references to access characters from the back of the string, e.g. -1 refers to the last character, -2 refers to the second last character and so on. (See the below figure).  While accessing an index out of the range will cause an indexerror. T E X T I L E 0 1 2 3 4 5 6 -7 -6 -5 -4 -3 -2 -1
  • 6. Repetition  The asterisk (*), when used between a string and an integer creates a new string with the old string repeated by the value of the integer.  The order of the arguments is not important.  Example:  Write a program to repeat a given string word=“hello” echo = word*5 print(echo) #output: hellohellohellohellohello
  • 7. String slicing  To access a range of characters in the string, method of slicing is used.  Slicing in a string is done by using a slicing operator (colon).  We can access substrings using slicing  For example:  Write a program to slice a given string C= “Whatever it takes” print(C) #output: Whatever it takes D=C[5:7] print(D) #output:ve E=C[9:11] print(E) #output: it
  • 8. String concatenation  Joining of two or more strings into a single one is called concatenation.  The + operator does this in python.  The * operator can be used to repeat the string for a given number of times.  For example:  Write a program to join two different string into a single one firstname = “aryadip” lastname = “dey” fullname=firstname + lastname print(fullname) #output: aryadipdey
  • 9. Splitting of string  By using split command we can get a list of the words in string.  For example:  Write a program to create a list of word from a given string a= "i am a boy” print(a) #output: i am a boy print(type(a)) #output: <class 'str'> print(len(a)) #output: 10 w= a.split() print(w) #output: ['i', 'am', 'a', 'boy'] print(type(w)) #output: <class 'list'> print(len(w)) #output: 4
  • 10. Split separator  Default separator is any space(space, newline, tab)  To specify any other separator, specify it explicitly.  For Example:  Write a program to split a string separated with a separator a= "fibre,yarn,fabric” print(a) #output: fibre,yarn,fabric print(type(a)) #output: <class 'str'> print(len(a)) #output: 17 w= a.split(',’) print(w) #output: ['fibre', 'yarn', 'fabric'] print(type(w)) #output: <class 'list'> print(len(w)) #output: 3
  • 11. Conversion of string  A string may be present in lower case or upper case. The string in lower case can be converted into upper case and vice versa using various methods of the str class.
  • 12. Conversion of string (Continued)
  • 13. Reference  Introduction to Python Programming Course Notes by Phil Spector  https://www.programiz.com/python-programming/online-compiler/  https://www.slideshare.net