String Functions
String Functions
isdigit() Returns True if characters of the given string are numeric. If whitespace or special symbols are part of str.isdigit()
the given string or the string is empty it returns False.
isalnum() Returns True if characters of the given string are either alphabets or numeric. If whitespace or special str.isalnum()
symbols are part of the given string or the string is empty it returns False.
islower() Returns True if the string is non-empty and has all lowercase alphabets, or has at least one character str.islower()
as lowercase alphabet and rest are non-alphabet characters.
isupper() Returns True if the string is non-empty and has all uppercase alphabets, or has at least one character str.isupper()
as uppercase character and rest are non-alphabet characters.
isspace() Returns True if the string is non-empty and all characters are white spaces (blank, tab, newline, str.isspace()
carriage return).
istitle() Returns True if the string is non-empty and title case, i.e., the first letter of every word in the string in str.istitle()
uppercase and rest in lowercase.
title() returns a copy of the original string and converts the first character each word of the string to a str.title()
capital (uppercase) letter while making all other characters in the string lowercase letters.
capitalize() returns a copy of the original string and converts the first character of the string to a capital str.capitalize()
(uppercase) letter while making all other characters in the string lowercase letters.
String Functions
Method Description Syntax
startswith() ▪ Al least one argument is required. str.startswith(substr[,start,end])
▪ Returns True if the given string starts with the supplied substring otherwise returns False.
endswith() ▪ Al least one argument is required. str.endswith(substr[,start,end])
▪ Returns True if the given string ends with the supplied substring otherwise returns False.
count() ▪ Returns the number of times the substring substr present in the given string. str.count(substr[,start,end])
▪ If we do not give start index and end index then searching starts from index 0 and ends at
length of the string
If the substring is not present in the given string, then the function returns 0.
find() ▪ Returns the first occurrence of index of substring str occurring in the given string. str.find(substr[,start,end])
▪ If we do not give start and end then searching starts from index 0 and ends at length of the
string.
If the substring is not present in the given string, then the function returns -1.
index() Same as find() function but raises an error/exception (ValueError) if the substring is not present in the str.index(substr[,start,end])
given string.
replace() ▪ It takes 3 arguments with the 3rd argument as an optional argument. str.replace(old, new[, count])
▪ returns a copy of the string where all occurrences of a substring are replaced with another
substring.