10 Must-read String Methods in Python

Here are top string methods in python helpful for data analytics projects.

IN THIS PAGE

  1. Python help
  2. Python find substring
  3. Upper function in python
  4. Lower function in python
  5. Strip method python
  6. Python string replace
  7. Split function in python
  8. Joining strings in python
  9. Python in and not in methods
  10. Endswith function in python

Python help

The python help provides details about methods.

 a="my own string"
b=help(a.upper)
print(b)

Result:

Help on built-in function upper:
upper() method of builtins.str instance
    Return a copy of the string converted to uppercase.

None

** Process exited - Return Code: 0 **
Press Enter to exit terminal

Python find substring

The python string find function provides index for substring.

a="my own string"
b=a.find('own')
print(b)

Result: 3 (index)
Advertisements

Upper function in python

The upper function in python convert’s string to upper case.

a="my own string"
b=a.upper()
print(b)
Result: MY OWN STRING (converts to upper case)

Lower function in python

The lower method in python converts the string to lower case.

a="my OWN string"
b=a.lower()
print(b)
Result: my own string (converts to lower)

Strip method python

The strip function in python strips a portion from the string.

a="my Own String"
b=a.strip('my')
print(b)
Resut: Own String (it strips only edges)
Advertisements

Python string replace

The python replace and python replaceall methods replaces existing string with new string.

a="my Own String"
b=a.replace('my', 'This is')
print(b)
Result: This is Own String (it replaces a portion of string)

Split function in python

The python split function splits string into list.

a = 'My Own String'
b= a.split()
print(b)
Result: ['My', 'Own', 'String']

Joining strings in python

Check out how to use join method in python.

Python in and not in methods

The python in method and not in methods checks presence of a char /or string.

a = 'My Own String'
b= 'My' in a
print(b)

Result : True

a = 'My Own String'
b= 'My' not in a
print(b)
Result: False

Endswith function in python

The python endswith function checks the ending portion of string.

a = 'My Own String'
b= a.endswith('String')
print(b)
Result: True
Related

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.