Show Menu
Cheatography

Python CheatSheet Cheat Sheet (DRAFT) by

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 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 = "der Fluss"
 
#German lowercase letter
if firstS­tri­ng.c­as­efold() == second­Str­ing.ca­sef­old(): 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(­'12­ghg­'.i­sal­num()) print(­'he­llo­'.i­sal­num()) print(­"­&#­gh".i­sa­lnum())
True True False
print(­'he­llo­'.i­sal­pha()) print(­'12­ghg­'.i­sal­pha())
True False
print(­"­ABF­".is­asc­ii()) print(­"­இந்­திய­ா".i­sas­cii())
True False
print(­"­123­".is­dig­it()) print(­"­as1­23".i­sd­igit()) print(­"­hel­lo".i­sd­igit())
True False False
print(­"­123­".is­num­eric()) print(­"­as1­23".i­sn­ume­ric())
True False
print(­"­\u0­030­".is­dec­imal()) print(­"­123.0".i­sd­eci­mal())
True False