STRING METHODS
INTRODUCTION
Python strings are immutable, meaning that all built-in string methods return a new string or value rather than altering the original data.
The general syntax of a python string method is:
string.method()Or ,if the string is stored in a variable:
variable.method()1.upper( ):
upper() is a Python string method that converts all lowercase characters into uppercase character will be ignored return a new string.
2.lower( ):
lower() is a Python string method that converts all uppercase characters in a string into lowercase character and returns a new string.
3.swap case( ):
swap case() is a Python string method that converts uppercase letters to lowercase and lowercase letters to uppercase, and returns a new string.
4.capitalize( ):
capitalize() is a Python string method that converts the first character of a string to uppercase and all remaining characters to lowercase, and returns a new string.
5.title( ):
title() is a Python string method that converts the first character of each word in a string to uppercase and the remaining characters to lowercase.
6.count( ):
Get Krishnaveni’s stories in your inbox
Join Medium for free to get updates from this writer.
count() is a Python string method that count the number of times a substring is present inside a string and returns the count as an integer.
7.replace( ):
replace() is a Python string method that replaces a substring with another substring and returns a new string.
Syntax:
string.replace(old, new)8.index( ):
index( ) is a python string method that returns the index (position) the location of a substring occuring in the first occurance of a string.
syntax:
string.index(substring)9.find( ):
find() is a Python string method that returns the index (position) of the first occurrence of a specified substring in a string. If the substring is not found, it returns -1.
10.strip( ):-
strip() is a Python string method that removes the specified characters from the beginning and end of a string and returns a new string.
syntax:
string.strip(characters)11.lstrip( ):
lstrip() is a Python string method that removes leading (left-side) whitespace or specified characters from a string and returns a new string.
12.rstrip( ):
rstrip() is a Python string method that removes trailing (right-side) whitespace or specified characters from a string and returns a new string.








