SlideShare a Scribd company logo
1 of 18
Download to read offline
STRINGS IN PYTHON
String in any programming language represents a sequence of
characters.Example-’Computer’ has a sequence of
characters-’C’,’o’,’m’,’p’,’u’,’t’,’e’,’r’.
For representing a string in python we use single or double
quotes.Example-
string=’I love Python’
string=”I love Python”
MANIPULATING STRINGS
Strings have various applications in python. Strings can be used for storing data,
manipulating it, representing address, name ,sentence etc. any data which is in
the form of text.
A single character in python is considered as a string having length 1.
Example-string1=’a’
print(string1)
How to extract individual characters from a string in python?
This can be done by a method called as Indexing.
Square brackets are used for accessing characters in string.
To represent a character’s position we use a number called index which starts from 0 and
ents at n-1(n represents number of characters in a string).
C O M P U T E R
0 1 2 3 4 5 6 7
In the given program we have tried to access character at 3rd position of string1 and for
string 2 character at 5th position.
We have negative indexing too where position of the character is determined from
the end of string and indexing starts from -1.
Example-C O M P U T E R
-8 -7 -6 -5 -4 -3 -2 -1
Reversing a string in python-
Reverse of a string can be obtained by writing[::-1].
Example-
REVERSING A STRING
For extracting a subset of a string we use the method of slicing. We can extract
the subset by using :.Example-
Further string in python is immutable. Means if we want to manipulate a string then a
new string will be created in which the change desired will be reflected. Means we
cannot make changes in an original string. Any change will be made in the new string
created.
Strings are like objects in python which has a set of built in functions which can be used
to manipulate strings.
There are various built in functions in python used to manipulate a string.
We use dot along with the variable name to invoke function.
FUNCTIONS USED FOR MANIPULATING STRINGS
Lower()function-used to convert all the characters in a string to lowercase
Uppercase()-Used to convert all the characters in a string to uppercase.
capitalize()-Used to return first character of a string in the uppercase.
len()-Used to find the string’s length.Spaces are also counted as a part of the
string.
find()-This function takes input and returns the index where that string is found in
the current string.If the string is not present in the current string then -1 is returned.
SOME OTHER FUNCTIONS
There are various other functions in the string objects which can be used to
manipulate strings in various ways.Other functions are-
replace()-used to replace substring inside a string.
isnumeric()-used to check numeric characters in a string.
index()-used to return index of substring.
Etc.
Various other operations are in strings which are performed on strings.
Compare two strings-== operator is used to compare 2 strings.We obtain false
here as the 2 strings are not same(although the text is same but the characters
are case sensitive in python).
Concatenation -is used to join 2 or more strings using + operator.
Iterating through a string-Iteration through a string can be done using for loop.

More Related Content

Similar to python (1).pdf

11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
ssuser8e50d8
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
jaychoudhary37
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
 

Similar to python (1).pdf (20)

Python ppt_118.pptx
Python ppt_118.pptxPython ppt_118.pptx
Python ppt_118.pptx
 
Python for loop
Python for loopPython for loop
Python for loop
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
 
Introduction To Programming with Python-3
Introduction To Programming with Python-3Introduction To Programming with Python-3
Introduction To Programming with Python-3
 
Sort Characters in a Python String Alphabetically
Sort Characters in a Python String AlphabeticallySort Characters in a Python String Alphabetically
Sort Characters in a Python String Alphabetically
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
LectureNotes-04-DSA
LectureNotes-04-DSALectureNotes-04-DSA
LectureNotes-04-DSA
 
STRINGS IN PYTHON
STRINGS IN PYTHONSTRINGS IN PYTHON
STRINGS IN PYTHON
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use cases
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings Methods
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
 
Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdf
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.ppt
 
unit 1.docx
unit 1.docxunit 1.docx
unit 1.docx
 
Python interview questions
Python interview questionsPython interview questions
Python interview questions
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Tuple Operation and Tuple Assignment in Python.pdf
Tuple Operation and Tuple Assignment in Python.pdfTuple Operation and Tuple Assignment in Python.pdf
Tuple Operation and Tuple Assignment in Python.pdf
 
UNIT 4 python.pptx
UNIT 4 python.pptxUNIT 4 python.pptx
UNIT 4 python.pptx
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 

Recently uploaded

sourabh vyas1222222222222222222244444444
sourabh vyas1222222222222222222244444444sourabh vyas1222222222222222222244444444
sourabh vyas1222222222222222222244444444
saurabvyas476
 
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
acoha1
 
原件一样伦敦国王学院毕业证成绩单留信学历认证
原件一样伦敦国王学院毕业证成绩单留信学历认证原件一样伦敦国王学院毕业证成绩单留信学历认证
原件一样伦敦国王学院毕业证成绩单留信学历认证
pwgnohujw
 
Audience Researchndfhcvnfgvgbhujhgfv.pptx
Audience Researchndfhcvnfgvgbhujhgfv.pptxAudience Researchndfhcvnfgvgbhujhgfv.pptx
Audience Researchndfhcvnfgvgbhujhgfv.pptx
Stephen266013
 
obat aborsi Banjarmasin wa 082135199655 jual obat aborsi cytotec asli di Ban...
obat aborsi Banjarmasin wa 082135199655 jual obat aborsi cytotec asli di  Ban...obat aborsi Banjarmasin wa 082135199655 jual obat aborsi cytotec asli di  Ban...
obat aborsi Banjarmasin wa 082135199655 jual obat aborsi cytotec asli di Ban...
siskavia95
 
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
yulianti213969
 
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
yulianti213969
 
obat aborsi Bontang wa 082135199655 jual obat aborsi cytotec asli di Bontang
obat aborsi Bontang wa 082135199655 jual obat aborsi cytotec asli di  Bontangobat aborsi Bontang wa 082135199655 jual obat aborsi cytotec asli di  Bontang
obat aborsi Bontang wa 082135199655 jual obat aborsi cytotec asli di Bontang
siskavia95
 
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
Amil baba
 
Displacement, Velocity, Acceleration, and Second Derivatives
Displacement, Velocity, Acceleration, and Second DerivativesDisplacement, Velocity, Acceleration, and Second Derivatives
Displacement, Velocity, Acceleration, and Second Derivatives
23050636
 

Recently uploaded (20)

Statistics Informed Decisions Using Data 5th edition by Michael Sullivan solu...
Statistics Informed Decisions Using Data 5th edition by Michael Sullivan solu...Statistics Informed Decisions Using Data 5th edition by Michael Sullivan solu...
Statistics Informed Decisions Using Data 5th edition by Michael Sullivan solu...
 
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
 
Genuine love spell caster )! ,+27834335081) Ex lover back permanently in At...
Genuine love spell caster )! ,+27834335081)   Ex lover back permanently in At...Genuine love spell caster )! ,+27834335081)   Ex lover back permanently in At...
Genuine love spell caster )! ,+27834335081) Ex lover back permanently in At...
 
sourabh vyas1222222222222222222244444444
sourabh vyas1222222222222222222244444444sourabh vyas1222222222222222222244444444
sourabh vyas1222222222222222222244444444
 
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
 
原件一样伦敦国王学院毕业证成绩单留信学历认证
原件一样伦敦国王学院毕业证成绩单留信学历认证原件一样伦敦国王学院毕业证成绩单留信学历认证
原件一样伦敦国王学院毕业证成绩单留信学历认证
 
Audience Researchndfhcvnfgvgbhujhgfv.pptx
Audience Researchndfhcvnfgvgbhujhgfv.pptxAudience Researchndfhcvnfgvgbhujhgfv.pptx
Audience Researchndfhcvnfgvgbhujhgfv.pptx
 
社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction社内勉強会資料_Object Recognition as Next Token Prediction
社内勉強会資料_Object Recognition as Next Token Prediction
 
The Significance of Transliteration Enhancing
The Significance of Transliteration EnhancingThe Significance of Transliteration Enhancing
The Significance of Transliteration Enhancing
 
obat aborsi Banjarmasin wa 082135199655 jual obat aborsi cytotec asli di Ban...
obat aborsi Banjarmasin wa 082135199655 jual obat aborsi cytotec asli di  Ban...obat aborsi Banjarmasin wa 082135199655 jual obat aborsi cytotec asli di  Ban...
obat aborsi Banjarmasin wa 082135199655 jual obat aborsi cytotec asli di Ban...
 
Credit Card Fraud Detection: Safeguarding Transactions in the Digital Age
Credit Card Fraud Detection: Safeguarding Transactions in the Digital AgeCredit Card Fraud Detection: Safeguarding Transactions in the Digital Age
Credit Card Fraud Detection: Safeguarding Transactions in the Digital Age
 
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
Jual Obat Aborsi Bandung (Asli No.1) Wa 082134680322 Klinik Obat Penggugur Ka...
 
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
obat aborsi Bontang wa 081336238223 jual obat aborsi cytotec asli di Bontang6...
 
How to Transform Clinical Trial Management with Advanced Data Analytics
How to Transform Clinical Trial Management with Advanced Data AnalyticsHow to Transform Clinical Trial Management with Advanced Data Analytics
How to Transform Clinical Trial Management with Advanced Data Analytics
 
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
 
obat aborsi Bontang wa 082135199655 jual obat aborsi cytotec asli di Bontang
obat aborsi Bontang wa 082135199655 jual obat aborsi cytotec asli di  Bontangobat aborsi Bontang wa 082135199655 jual obat aborsi cytotec asli di  Bontang
obat aborsi Bontang wa 082135199655 jual obat aborsi cytotec asli di Bontang
 
MATERI MANAJEMEN OF PENYAKIT TETANUS.ppt
MATERI  MANAJEMEN OF PENYAKIT TETANUS.pptMATERI  MANAJEMEN OF PENYAKIT TETANUS.ppt
MATERI MANAJEMEN OF PENYAKIT TETANUS.ppt
 
Seven tools of quality control.slideshare
Seven tools of quality control.slideshareSeven tools of quality control.slideshare
Seven tools of quality control.slideshare
 
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
 
Displacement, Velocity, Acceleration, and Second Derivatives
Displacement, Velocity, Acceleration, and Second DerivativesDisplacement, Velocity, Acceleration, and Second Derivatives
Displacement, Velocity, Acceleration, and Second Derivatives
 

python (1).pdf

  • 1. STRINGS IN PYTHON String in any programming language represents a sequence of characters.Example-’Computer’ has a sequence of characters-’C’,’o’,’m’,’p’,’u’,’t’,’e’,’r’. For representing a string in python we use single or double quotes.Example- string=’I love Python’ string=”I love Python”
  • 2.
  • 3. MANIPULATING STRINGS Strings have various applications in python. Strings can be used for storing data, manipulating it, representing address, name ,sentence etc. any data which is in the form of text. A single character in python is considered as a string having length 1. Example-string1=’a’ print(string1)
  • 4. How to extract individual characters from a string in python? This can be done by a method called as Indexing. Square brackets are used for accessing characters in string. To represent a character’s position we use a number called index which starts from 0 and ents at n-1(n represents number of characters in a string). C O M P U T E R 0 1 2 3 4 5 6 7 In the given program we have tried to access character at 3rd position of string1 and for string 2 character at 5th position.
  • 5.
  • 6. We have negative indexing too where position of the character is determined from the end of string and indexing starts from -1. Example-C O M P U T E R -8 -7 -6 -5 -4 -3 -2 -1 Reversing a string in python- Reverse of a string can be obtained by writing[::-1]. Example-
  • 7. REVERSING A STRING For extracting a subset of a string we use the method of slicing. We can extract the subset by using :.Example-
  • 8. Further string in python is immutable. Means if we want to manipulate a string then a new string will be created in which the change desired will be reflected. Means we cannot make changes in an original string. Any change will be made in the new string created. Strings are like objects in python which has a set of built in functions which can be used to manipulate strings. There are various built in functions in python used to manipulate a string. We use dot along with the variable name to invoke function.
  • 9. FUNCTIONS USED FOR MANIPULATING STRINGS Lower()function-used to convert all the characters in a string to lowercase
  • 10.
  • 11. Uppercase()-Used to convert all the characters in a string to uppercase.
  • 12. capitalize()-Used to return first character of a string in the uppercase.
  • 13. len()-Used to find the string’s length.Spaces are also counted as a part of the string.
  • 14. find()-This function takes input and returns the index where that string is found in the current string.If the string is not present in the current string then -1 is returned.
  • 15. SOME OTHER FUNCTIONS There are various other functions in the string objects which can be used to manipulate strings in various ways.Other functions are- replace()-used to replace substring inside a string. isnumeric()-used to check numeric characters in a string. index()-used to return index of substring. Etc. Various other operations are in strings which are performed on strings.
  • 16. Compare two strings-== operator is used to compare 2 strings.We obtain false here as the 2 strings are not same(although the text is same but the characters are case sensitive in python).
  • 17. Concatenation -is used to join 2 or more strings using + operator.
  • 18. Iterating through a string-Iteration through a string can be done using for loop.