String Methodz Flashcards
.capitalize()
Converts the first letter in string to uppercase.
.casefold()
Converts the entire string to lowercase.
.count()
Returns the number of times a specified value occurs in a string.
.count(value, start, end)
value = required
start = optional, default 0
end = optional, default end of string
.encode()
Returns an encoded version of the string, using specified encoding.
.encode(encoding=encoding, errors=errors)
encoding = optional, default UTF-8
errors = optional, specifies error handling (i.e. strict, ignore, backslashreplace)
.endswith()
Returns true if the string ends with the specified value.
.endswith(value, start, end)
value = string
start = optional (default 0)
end = optional (default end of string)
.find()
Searches the string for a specified value and returns the position of where it was found. Returns -1 if not found.
.find(value, start, end)
.format()
Formats specified values in a string; replaces placeholders defined with curly brackets.
.format(values)
.isalnum()
Returns True if all characters in the string are alphanumeric (a-z, 0-9).
.isalpha()
Returns True if all characters in the string are in the alphabet (a-z).
.isascii()
Returns True if all characters in the string are ASCII characters (a-z, 0-9, some special chars like $, &, *).
.isdecimal()
Returns True if all characters in the string are decimals (0-9).
.isdigit()
Returns True if all characters in the string are digits (0-9).
.isidentifier()
Returns True if the string is a valid identifier (a-z, 0-9 and _).
.islower()
Returns True if all characters in the string are lower case.
.isnumeric()
Returns True if all characters in the string are numeric.