Python String Functions
Python String Functions
Made By:
Converts all
lowercase letters
str.upper() "hello".upper() "HELLO"
in a string to
uppercase.
Converts all
uppercase letters
str.lower() "HELLO".lower() "hello"
in a string to
lowercase.
Capitalizes the
"hello
str.capitalize() first character of "Hello world"
world".capitalize()
the string.
Capitalizes the
"hello
str.title() first letter of each "Hello World"
world".title()
word in the string.
Removes leading
and trailing
str.strip([chars]) characters " hello ".strip() "hello"
(whitespace by
default).
Returns True if
all characters "hello123".isalnu
str.isalnum() True
in the string are m()
alphanumeric.
Returns the
number of non-
"hello
str.count(sub[, overlapping
world".count("o" 2
start[, end]]) occurrences of
)
substring sub in
the string.
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."