Cheatography
https://cheatography.com
Basic Python CheatSheet for the built-in methods of String, Lists, Sets, Tuples and Dictionaries
This is a draft cheat sheet. It is a work in progress and is not finished yet.
String Methods
mystr = "This is the eXamPle seNtenCe" |
mystr.capitalize() |
This is the example sentence |
#Capitalizes the first character/letter in the whole string |
mystr.title() |
This Is The Example Sentence |
#Capitalizes the first letter in each word |
mystr.upper() |
THIS IS THE EXAMPLE SENTENCE |
#Converts all letters to uppercase |
mystr.lower() |
this is the example sentence |
#Converts all letters to lowercase |
mystr.casefold() |
this is the example sentence |
#used for caseless matching |
mystr.swapcase() |
tHIS IS THE ExAMpLE SEnTENcE |
#Converts lowercase letters to upper and uppercase letters to lower |
firstString = "der Fluß" # German lowercase letter secondString = "der Fluss" |
|
String Methods
firstString = "der Fluß"; secondString = "der Fluss" |
|
#German lowercase letter |
if firstString.casefold() == secondString.casefold(): print('True') |
True |
''' The German lowercase letter ß is equivalent to ss. However, since ß is already lowercase, the lower() method does nothing to it. But, casefold() converts it to ss''' |
print('12ghg'.isalnum()) print('hello'.isalnum()) print("&#gh".isalnum()) |
True True False |
print('hello'.isalpha()) print('12ghg'.isalpha()) |
True False |
print("ABF".isascii()) print("இந்தியா".isascii()) |
True False |
print("123".isdigit()) print("as123".isdigit()) print("hello".isdigit()) |
True False False |
print("123".isnumeric()) print("as123".isnumeric()) |
True False |
print("\u0030".isdecimal()) print("123.0".isdecimal()) |
True False |
|