Strings: Topics: String Class Associated Methods Examples
Strings: Topics: String Class Associated Methods Examples
Topics:
String Class
Associated Methods
Examples
Strings
String Class
You can display a string literal with
the print() function:
print("Hello")
print('Hello')
Python has a set of built-in methods that you can use on strings.
capitalize()
Converts the first character to upper case
casefold()
endswith()
Returns true if the string ends with the specified value
index()
Searches the string for a specified value and returns the
position of where it was found
isalnum()
Returns True if all characters in the string are alphanumeric
isalpha()
String Returns True if all characters in the string are in the alphabet
Methods isdecimal()
Returns True if all characters in the string are decimals
isdigit()
Returns True if all characters in the string are digits
islower()
Returns True if all characters in the string
are lower case
isprintable()
String
Returns True if all characters in the string
are printable
Methods isspace()
Returns True if all characters in the string
are whitespaces
Istitle()
Returns True if the string follows the
rules of a title
isupper()
Returns True if all characters in the string are upper
case
join()
Joins the elements of an iterable to the end of the
string
String lower()
Methods
Converts a string into lower case
lstrip()
Returns a left trim version of the string
rstrip()
Returns a right trim version of the string
strip()
Returns a trimmed version of the string
split()
Splits the string at the specified separator, and
returns a list
String rsplit()
Methods
Splits the string at the specified separator, and
returns a list
strartswith()
Returns true if the string starts with the specified
value
swapcase()
Swaps cases, lower case becomes upper case and
vice versa
title()
Converts the first character of
each word to upper case
String upper()
Converts a string into upper
Methods case
splitlines()
Splits the string at line breaks
and returns a list