CENTRE FOR BIOINFORMATICS
PRESENTATION ON : STRING MANIPULATION IN PYTHON
SUBMITTED TO: SUBMITTED BY:
DR.DEEPSHIKHA YANSHIKA
M.SC BIOINFORMATICS
(FINAL)
content
 Introduction to string
 Properties of string datatype
 Basic string creation
 String concatenation
 Accessing string through index
 String slicing
 Basic functions and methods
Python string
 A Python string is a datatype that stores sequence of characters.
 String enclosed within either single quotes (‘ ‘) or double quotes (" ").
 It is an immutable data type, which means once a string is created, it
cannot be modified.
 However, it is possible to create a new string by concatenating two or
more strings.
Properties of String Data Type in Python
 Immutable: Strings in Python are immutable, which means that once a string is
created, it cannot be modified.
 Sequence: Strings in Python are sequences of characters, which means that you can
access individual characters in a string using indexing and slicing.
 Concatenation: Strings in Python can be concatenated using the + operator. For
example, "Hello" + "World" would result in the string "HelloWorld".
 Methods: Python provides a range of built-in methods that can be used to
manipulate strings, such as the upper() and lower() methods to convert strings to
uppercase and lowercase, respectively.
Basic string creation
String concatenation
String concatenation
Input Output
Accessing Characters in a String
Indexing
 Indexing allows you to access a specific character in a string by its
position.
 Python uses zero-based indexing, so the first character is at index 0, the
second at index 1, and so on.
 Negative indexing is also supported, where -1 refers to the last character,
-2 to the second last, and so forth.
Here’s how you can use indexing to access characters:
Python Program showing string slicing
Positive and negative indexing
Some commonly used string functions in
python
Case Changing of Python String
 lower(): Converts all uppercase characters in a string into
lowercase.
 upper(): Converts all lowercase characters in a string into
uppercase.
 title(): Convert string to title case.
 swapcase(): Swap the cases of all characters in a string.
 capitalize(): Convert the first character of a string to uppercase.
String- lower case to upper case
String-upper case to lower case
Str.title()- converts the first character to the upper case and rest to the lower case.
Str.capitalize()- convert the first character to the uppercase
 Str.endswith() – this function return true ,if the given string is ends with the
character enclosed within the brackets.
str.replace(old,new)- replace old value to the new value.
Str.find(word)- return the index of first letter of your
desired word.
Str.count(substring)- counts the occurrence of substring.
presentation on python string manipulation
presentation on python string manipulation
presentation on python string manipulation

presentation on python string manipulation

  • 1.
    CENTRE FOR BIOINFORMATICS PRESENTATIONON : STRING MANIPULATION IN PYTHON SUBMITTED TO: SUBMITTED BY: DR.DEEPSHIKHA YANSHIKA M.SC BIOINFORMATICS (FINAL)
  • 2.
    content  Introduction tostring  Properties of string datatype  Basic string creation  String concatenation  Accessing string through index  String slicing  Basic functions and methods
  • 3.
    Python string  APython string is a datatype that stores sequence of characters.  String enclosed within either single quotes (‘ ‘) or double quotes (" ").  It is an immutable data type, which means once a string is created, it cannot be modified.  However, it is possible to create a new string by concatenating two or more strings.
  • 4.
    Properties of StringData Type in Python  Immutable: Strings in Python are immutable, which means that once a string is created, it cannot be modified.  Sequence: Strings in Python are sequences of characters, which means that you can access individual characters in a string using indexing and slicing.  Concatenation: Strings in Python can be concatenated using the + operator. For example, "Hello" + "World" would result in the string "HelloWorld".  Methods: Python provides a range of built-in methods that can be used to manipulate strings, such as the upper() and lower() methods to convert strings to uppercase and lowercase, respectively.
  • 5.
  • 7.
  • 8.
  • 9.
    Accessing Characters ina String Indexing  Indexing allows you to access a specific character in a string by its position.  Python uses zero-based indexing, so the first character is at index 0, the second at index 1, and so on.  Negative indexing is also supported, where -1 refers to the last character, -2 to the second last, and so forth.
  • 10.
    Here’s how youcan use indexing to access characters:
  • 12.
    Python Program showingstring slicing
  • 13.
  • 14.
    Some commonly usedstring functions in python Case Changing of Python String  lower(): Converts all uppercase characters in a string into lowercase.  upper(): Converts all lowercase characters in a string into uppercase.  title(): Convert string to title case.  swapcase(): Swap the cases of all characters in a string.  capitalize(): Convert the first character of a string to uppercase.
  • 15.
    String- lower caseto upper case
  • 16.
  • 17.
    Str.title()- converts thefirst character to the upper case and rest to the lower case.
  • 18.
    Str.capitalize()- convert thefirst character to the uppercase
  • 19.
     Str.endswith() –this function return true ,if the given string is ends with the character enclosed within the brackets. str.replace(old,new)- replace old value to the new value. Str.find(word)- return the index of first letter of your desired word. Str.count(substring)- counts the occurrence of substring.