Show Menu
Cheatography

Popular Methods Cheat Sheet Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

String Methods

str.is­digit()
Returns Boolean
"24".isdigit()
str.ti­tle()
Capitalize Every First Letter
"­hello world".t­itle()
str.lo­wer()
Lowercase first Letter
"­Hello World".l­ower()
str.up­per()
Capitalizes First letter
"­hello world".u­pper()
str.startswith(prefix[, start[, end]])
Returns Boolean
"Hello World".startswith("Hello")
str.sp­lit­(se­p=None, maxspl­it=-1)
Returns a list
"The, fox, is, crazy".s­pl­it(',')
str.jo­in(­ite­rable)
Glues an iterable together with a string
"­\n".j­oi­n([­"­Thr­ee", "­new­", "­Lin­es"])
str.en­dsw­ith­(pr­efix[, start[, end]])
Returns a Boolean
"­Hello World".e­nd­swi­th(­"­Wor­ld")
str.re­pla­ce(old, new[, count])
Returns a new string
"Hello n World".replace("n", "and")
str.fo­rmat(args, *kwargs)
Insert args/k­wargs into a string
"The {} jumped {}.".format(animal, height)

Built-in Functions

all(iterable)
Check if all elements are True. Returns boolean.
all([True, True, True)]
any(iterable)
Check if any element is True. Returns Boolean
any([True, False, False])
divmod(a, b)
Returns quotient and remainder
quotient, remainder = divmod(24, 7)
int()
Returns an integer
int("24")
max()
Returns largest item in an iterable
max([1, 10, 4])
map()
Returns a map object with a function applied to each element
map(str, [1, 2, 3])
min()
Returns smallest item in an iterable
min([1, 10, 4])
reversed()
Reverse order of a squence
revers­e([1, 2, 3, 4])
sorted(iterable[, key][, reverse])
Returns new iterable sorted by specif­ication
sorted([5, 2, 3, 1, 4])
str()
Returns a string
str(24)
sum(iterable[, start])
Returns the sum of an iterable
sum([1, 2, 3, 4])
zip(*i­ter­ables)
Creates a sequence, where each corres­ponding element is paired
zip([1, 2, 3], [4, 5, 6])
 

Reminders

Watch out for python 2.7 code and libraries. They are not compatible with Python 3
Ints, Floats, Complex, Booleans, Strings, Tuples, and bytes are immutable
Dictio­naries are by default unordered prior to Python 3.6
Readab­ility is more important than speed 95% of the time
Always put a space between operators: 5 + 3
Use is instead of == when checking for None.
Don't use blind excepts in try/except blocks.
Everything is a public method. Nothing is completely private.
Find out what tools are available in the standard library. Don't reinvent the wheel.
Don't over optimize your code when writing it for the first time.
List, Generator, and Dictionary compre­hen­sions are your friends. Don't make them an enemy through over compli­cation.
Remember T3. Test, Test, Test.
Refactor your code after your have finished writing it the first time.
The differ­ences in pollin­g/b­locking vs non-po­lli­ng/­non­-bl­ocking