Python String Methods – Syntax, Use &
Example
Sr. No. String Method Use / Purpose Example Output
(Syntax)
1 str Represents a "I am very I am very happy
string object happy"
2 type(str) Returns the type("Hello") <class 'str'>
data type of the
object
3 len(str) Returns the len("Hello") 5
number of
characters in
the string
4 [Link]() Converts all "hello".upper() HELLO
characters to
uppercase
5 [Link]() Converts all "HELLO".lower( hello
characters to )
lowercase
6 [Link]() Capitalizes the "hello Hello world
first character world".capitaliz
e()
7 [Link]() Capitalizes first "hello Hello World
letter of each world".title()
word
8 [Link]() Returns True if "hello".islower( True
all characters )
are lowercase
9 [Link]() Returns True if "HELLO".isuppe True
all characters r()
are uppercase
10 [Link]() Returns True if "Hello True
in title case World".istitle()
11 [Link]() Returns True if "1234".isnumer True
all characters ic()
are numeric
12 [Link]() Returns True if "Hello".isalpha( True
all characters )
are alphabets
13 [Link]() Returns True if "Hello123".isal True
all are num()
alphanumeric
(no
space/symbol)
14 [Link]() Returns True if " ".isspace() True
only
whitespace
15 [Link](sub) Returns first "hello".index("e 1
index of ")
substring
(error if not
found)
16 [Link](sub) Returns last "happy".rindex( 3
index of "p")
substring
(error if not
found)
17 [Link](sub) Counts "hello".count("l 2
occurrences of ")
a substring
18 [Link](chars) Removes " India ".strip() India
leading and
trailing
characters
19 [Link](chars Removes " India ".rstrip() India
) trailing
characters
20 [Link](chars) Removes " India ".lstrip() India
leading
characters
21 [Link](sub) Returns first "python".find("t 2
index of h")
substring or -1
22 [Link](sub) Returns last "python".rfind( 2
index of "t")
substring or -1
23 [Link](sep) Splits string by "a b c".split(" ") ['a', 'b', 'c']
separator and
returns a list
24 [Link]("a") Splits string "rajaram".split( ['r', 'j', 'r', 'm']
where "a" is "a")
found
25 "sep".join(list) Joins list ".".join(["a","b"] a.b
elements with )
separator
26 [Link](old, Replaces a "cloud".replace( DevOps
new) substring with "cloud",
another "DevOps")
27 [Link](p Checks if string "python".starts True
refix) starts with the with("py")
given substring
28 [Link](su Checks if string "easy".endswit True
ffix) ends with the h("sy")
given substring