String Functions
Made By:
Yadneyesh (Curious Coder) Find More PDFs on Our Telegram Channel
[Link] @Curious_Coder
Method Description Example Output
Converts all
lowercase letters
[Link]() "hello".upper() "HELLO"
in a string to
uppercase.
Converts all
uppercase letters
[Link]() "HELLO".lower() "hello"
in a string to
lowercase.
Capitalizes the
"hello
[Link]() first character of "Hello world"
world".capitalize()
the string.
Capitalizes the
"hello
[Link]() first letter of each "Hello World"
world".title()
word in the string.
Removes leading
and trailing
[Link]([chars]) characters " hello ".strip() "hello"
(whitespace by
default).
500+ Coding Projects with Source
We Post CSE Notes for You
Code Visit: [Link]
Splits the string into
[Link](sep=No a list of substrings "hello
["hello", "world"]
ne, maxsplit=-1) based on a world".split()
delimiter.
Joins the elements
of an iterable into a
single string, " ".join(["hello",
[Link](iterable) "hello world"
separated by the "world"])
string on which it is
called.
Returns the lowest
index in the string "hello
[Link](sub[,
where substring sub world".find("worl 6
start[, end]])
is found, or -1 if not d")
found.
[Link](pr Returns True if the "hello
efix[, start[, string starts with the world".startswith True
end]]) specified prefix. ("hello")
[Link](suf Returns True if the "hello
fix[, start[, string ends with the world".endswith(" True
end]]) specified suffix. world")
Returns True if all
characters in the
[Link]() "hello".isalpha() True
string are
alphabetic.
500+ Coding Projects with Source
We Post CSE Notes for You
Code Visit: [Link]
Returns True if
all characters
[Link]() "12345".isdigit() True
in the string are
digits.
Returns True if
all characters "hello123".isalnu
[Link]() True
in the string are m()
alphanumeric.
Returns the
number of non-
"hello
[Link](sub[, overlapping
world".count("o" 2
start[, end]]) occurrences of
)
substring sub in
the string.
Formats the "Hello, {}. You
Hello, Alice. You
[Link](*arg string using the are {} years
are 30 years
s, **kwargs) provided old.".format("Ali
old.
arguments. ce", 30)
name = "Alice";
Formats strings
age = 30; Hello, Alice. You
using
f-string f"Hello, {name}. are 30 years
embedded
You are {age} old.
expressions.
years old."
500+ Coding Projects with Source
We Post CSE Notes for You
Code Visit: [Link]