Python String Methods Complete
Python String Methods Complete
capitalize()
Examples:
casefold()
Returns a casefolded copy of the string. Casefolded strings are suitable for caseless comparisons.
Examples:
center()
Examples:
count()
Examples:
"banana".count("a") # Output: 3
encode()
Examples:
endswith()
Examples:
expandtabs()
Examples:
find()
Examples:
"hello".find("e") # Output: 1
"hello".find("x") # Output: -1
format()
Examples:
index()
Returns the lowest index of the substring; raises an exception if not found.
Examples:
"hello".index("e") # Output: 1
"hello".index("x") # Raises ValueError
isalnum()
Examples:
isalpha()
Examples:
isdigit()
Examples:
islower()
Examples:
isnumeric()
Examples:
"123".isnumeric() # Output: True
isspace()
Examples:
istitle()
Examples:
isupper()
Examples:
join()
Examples:
ljust()
Left-aligns the string using a specified width.
Examples:
lower()
Examples:
lstrip()
Examples:
partition()
Examples:
replace()
Examples:
rfind()
Returns the highest index of the substring if found; otherwise, -1.
Examples:
"hello".rfind("l") # Output: 3
"hello".rfind("x") # Output: -1
rindex()
Returns the highest index of the substring; raises an exception if not found.
Examples:
"hello".rindex("l") # Output: 3
rjust()
Examples:
rstrip()
Examples:
split()
Examples:
Examples:
startswith()
Examples:
strip()
Examples:
swapcase()
Examples:
title()
Examples:
translate()
upper()
Examples:
zfill()
Examples: