Python Strings: Replace, Join, Split, Reverse, Uppercase & Lowercase

In Python everything is object and string are an object too. Python string can be created simply by enclosing characters in the double quote.

For example:

var = “Hello World!”

In this tutorial, we will learn –

Various String Operators

There are various string operators that can be used in different ways like concatenating different string.

Suppose if a=guru and b=99 then a+b= “guru99”. Similarly, if you are using a*2, it will “GuruGuru”. Likewise, you can use other operators in string.

Python 2 Example


Since Python is an object-oriented programming language, many functions can be applied to Python objects. A notable feature of Python is its indenting source statements to make the code easier to read.

  • Accessing values through slicing – square brackets are used for slicing along with the index or indices to obtain a substring.
    • In slicing, if range is declared [1:5], it can actually fetch the value from range [1:4]
  • You can update Python String by re-assigning a variable to another string
  • Method replace() returns a copy of the string in which the occurrence of old is replaced with new.
    • Syntax for method replace: oldstring.replace(“value to change”,”value to be replaced”)
  • String operators like [], [ : ], in, Not in, etc. can be applied to concatenate the string, fetching or inserting specific characters into the string, or to check whether certain character exist in the string
  • Other string operations include
    • Changing upper and lower case
    • Join function to glue any character into the string
    • Reversing string
    • Split string