You are on page 1of 2

Python CheatSheet Cheat Sheet

by Sivasuryat (Sivasurya) via cheatography.com/146739/cs/31786/

String Methods

mystr = "This is the eXamPle seNten​Ce"


mystr.c​ap​ita​lize() This is the example sentence #Capit​alizes the first charac​ter​/letter in the whole string
mystr.t​itle() This Is The Example Sentence #Capit​alizes the first letter in each word

mystr.u​pper() THIS IS THE EXAMPLE SENTENCE #Converts all letters to uppercase


mystr.l​ower() this is the example sentence #Converts all letters to lowercase
mystr.c​as​efold() this is the example sentence #used for caseless matching
mystr.s​wa​pcase() tHIS IS THE ExAMpLE SEnTENcE #Converts lowercase letters to upper and uppercase letters to lower
firstS​tring = "der Fluß" # German lowercase letter second​String = "der Fluss"

String Methods

firstS​tring = "der Fluß"; second​String = #German lowercase letter


"der Fluss"
if firstS​tri​ng.c​as​efold() == second​Str​‐ True ''' The German lowercase letter ß is equivalent to ss. However, since ß is already lowercase,
ing.ca​sef​old(): print(​'True') the lower() method does nothing to it. But, casefold() converts it to ss'''
print(​'12​ghg​'.i​sal​num()) print(​'he​llo​'.i​sal​‐ True True False
num()) print(​"​&#​gh".i​sa​lnum())
print(​'he​llo​'.i​sal​pha()) print(​'12​ghg​'.i​sal​‐ True False
pha())
print("ABF".isascii()) print("இ திய◌ா".i‐ True False
sas​cii())
print(​"​123​".is​dig​it()) print(​"​as1​23".i​sd​‐ True False False
igit()) print(​"​hel​lo".i​sd​igit())
print(​"​123​".is​num​eric()) print(​"​as1​23".i​‐ True False
sn​ume​ric())
print(​"​\u0​030​".is​dec​imal()) print(​"​‐ True False
123.0".i​sd​eci​mal())

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

You might also like