Here are top string methods in python helpful for data analytics projects.
IN THIS PAGE
- Python help
- Python find substring
- Upper function in python
- Lower function in python
- Strip method python
- Python string replace
- Split function in python
- Joining strings in python
- Python in and not in methods
- 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)
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)
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