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

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

PPT
Introduction To Python
shailaja30
 
PPTX
Introduction on basic python and it's application
sriram2110
 
PDF
9 character string &amp; string library
MomenMostafa
 
ODP
Python slide.1
Aswin Krishnamoorthy
 
PPTX
foundation class python week 4- Strings.pptx
MarufFarhanRigan1
 
PDF
Python Lab Manual for First year Engineering students
AkshayAgrawal34132
 
PPTX
Engineering string(681) concept ppt.pptx
ChandrashekarReddy98
 
PPTX
Introduction to python programming ( part-3 )
Ziyauddin Shaik
 
PPTX
C-Arrays & Strings (computer programming).pptx
yusuph2410
 
PDF
Strings in Python
nitamhaske
 
PDF
05 c++-strings
Kelly Swanson
 
PPTX
Python 3.pptx
HarishParthasarathy4
 
PDF
Python- strings
Krishna Nanda
 
PDF
stringsinpython-181122100212.pdf
paijitk
 
PPTX
PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT
factsandknowledge94
 
PDF
23UCACC11 Python Programming (MTNC) (BCA)
ssuser7f90ae
 
PDF
Python-Cheat-Sheet.pdf
Mohd Aves Malik
 
PPTX
Keep it Stupidly Simple Introduce Python
SushJalai
 
PPTX
ARRAY's in C Programming Language PPTX.
MSridhar18
 
PPTX
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
Introduction To Python
shailaja30
 
Introduction on basic python and it's application
sriram2110
 
9 character string &amp; string library
MomenMostafa
 
Python slide.1
Aswin Krishnamoorthy
 
foundation class python week 4- Strings.pptx
MarufFarhanRigan1
 
Python Lab Manual for First year Engineering students
AkshayAgrawal34132
 
Engineering string(681) concept ppt.pptx
ChandrashekarReddy98
 
Introduction to python programming ( part-3 )
Ziyauddin Shaik
 
C-Arrays & Strings (computer programming).pptx
yusuph2410
 
Strings in Python
nitamhaske
 
05 c++-strings
Kelly Swanson
 
Python 3.pptx
HarishParthasarathy4
 
Python- strings
Krishna Nanda
 
stringsinpython-181122100212.pdf
paijitk
 
PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT
factsandknowledge94
 
23UCACC11 Python Programming (MTNC) (BCA)
ssuser7f90ae
 
Python-Cheat-Sheet.pdf
Mohd Aves Malik
 
Keep it Stupidly Simple Introduce Python
SushJalai
 
ARRAY's in C Programming Language PPTX.
MSridhar18
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 

More from AryadipDey (6)

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

Recently uploaded (20)

PPTX
Day2 B2 Best.pptx
helenjenefa1
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Day2 B2 Best.pptx
helenjenefa1
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Ad

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