This cheat sheet summarizes common string methods in Python. It provides examples of using string methods like capitalize(), title(), upper(), lower(), casefold(), swapcase() as well as methods to check the type of a string like isalpha(), isdigit(), isnumeric(), isdecimal(). It also demonstrates using casefold() to check equivalence between strings with different cases like "der Fluß" and "der Fluss" in German.
This cheat sheet summarizes common string methods in Python. It provides examples of using string methods like capitalize(), title(), upper(), lower(), casefold(), swapcase() as well as methods to check the type of a string like isalpha(), isdigit(), isnumeric(), isdecimal(). It also demonstrates using casefold() to check equivalence between strings with different cases like "der Fluß" and "der Fluss" in German.
This cheat sheet summarizes common string methods in Python. It provides examples of using string methods like capitalize(), title(), upper(), lower(), casefold(), swapcase() as well as methods to check the type of a string like isalpha(), isdigit(), isnumeric(), isdecimal(). It also demonstrates using casefold() to check equivalence between strings with different cases like "der Fluß" and "der Fluss" in German.
by Sivasuryat (Sivasurya) via cheatography.com/146739/cs/31786/
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 = #German lowercase letter
"der Fluss" if firstString.casefold() == secondStr‐ True ''' The German lowercase letter ß is equivalent to ss. However, since ß is already lowercase, ing.casefold(): print('True') the lower() method does nothing to it. But, casefold() converts it to ss''' print('12ghg'.isalnum()) print('hello'.isal‐ True True False num()) print("&#gh".isalnum()) print('hello'.isalpha()) print('12ghg'.isal‐ True False pha()) print("ABF".isascii()) print("இ திய◌ா".i‐ True False sascii()) print("123".isdigit()) print("as123".isd‐ True False False igit()) print("hello".isdigit()) print("123".isnumeric()) print("as123".i‐ True False snumeric()) print("\u0030".isdecimal()) print("‐ True False 123.0".isdecimal())
By Sivasuryat (Sivasurya) Not published yet. Sponsored by Readable.com
cheatography.com/sivasurya/ Last updated 21st April, 2022. Measure your website readability! Page 2 of 2. https://readable.com