0% found this document useful (0 votes)
2 views2 pages

Python String Methods Table

The document provides a comprehensive overview of various Python string methods, including their syntax, purpose, and examples. Each method is listed with a brief description of its function and an example demonstrating its use. Key methods include str.upper(), str.lower(), str.strip(), and str.split(), among others.

Uploaded by

patilharshada974
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python String Methods Table

The document provides a comprehensive overview of various Python string methods, including their syntax, purpose, and examples. Each method is listed with a brief description of its function and an example demonstrating its use. Key methods include str.upper(), str.lower(), str.strip(), and str.split(), among others.

Uploaded by

patilharshada974
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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 str.upper() Converts all "hello".upper() HELLO
characters to
uppercase
5 str.lower() Converts all "HELLO".lower( hello
characters to )
lowercase
6 str.capitalize() Capitalizes the "hello Hello world
first character world".capitaliz
e()
7 str.title() Capitalizes first "hello Hello World
letter of each world".title()
word
8 str.islower() Returns True if "hello".islower( True
all characters )
are lowercase
9 str.isupper() Returns True if "HELLO".isuppe True
all characters r()
are uppercase
10 str.istitle() Returns True if "Hello True
in title case World".istitle()
11 str.isnumeric() Returns True if "1234".isnumer True
all characters ic()
are numeric
12 str.isalpha() Returns True if "Hello".isalpha( True
all characters )
are alphabets
13 str.isalnum() Returns True if "Hello123".isal True
all are num()
alphanumeric
(no
space/symbol)
14 str.isspace() Returns True if " ".isspace() True
only
whitespace
15 str.index(sub) Returns first "hello".index("e 1
index of ")
substring
(error if not
found)
16 str.rindex(sub) Returns last "happy".rindex( 3
index of "p")
substring
(error if not
found)
17 str.count(sub) Counts "hello".count("l 2
occurrences of ")
a substring
18 str.strip(chars) Removes " India ".strip() India
leading and
trailing
characters
19 str.rstrip(chars Removes " India ".rstrip() India
) trailing
characters
20 str.lstrip(chars) Removes " India ".lstrip() India
leading
characters
21 str.find(sub) Returns first "python".find("t 2
index of h")
substring or -1
22 str.rfind(sub) Returns last "python".rfind( 2
index of "t")
substring or -1
23 str.split(sep) Splits string by "a b c".split(" ") ['a', 'b', 'c']
separator and
returns a list
24 str.split("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 str.replace(old, Replaces a "cloud".replace( DevOps
new) substring with "cloud",
another "DevOps")
27 str.startswith(p Checks if string "python".starts True
refix) starts with the with("py")
given substring
28 str.endswith(su Checks if string "easy".endswit True
ffix) ends with the h("sy")
given substring

You might also like