Show Menu
Cheatography

new Python infoz! Cheat Sheet (DRAFT) by

Aspects of Python that metamad is haphazardly learning... To non-metamads, these will probably seem pretty random!

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

python randomz

What's __init­__.py?
Placing an __init­­__.py in a directory marks the contents of the dir as a Python package

For example,

somedi­­r/­_­_­in­­it.py
somedi­­r/­m­y­th­­ing.py

allows

import somedi­­r.m­­y­thing
# dir containing somedir should be on your path

(__ini­­t__.py is usually empty, but you can use it to indicate more convenient importing options)
   

python randomz 2

Difference bw sorted­(my­_list) and my_lis­t.s­ort­ed()?
sort() is method of a list, sorts the list IN PLACE, does not return a list; sorted() is a built-in function, does not sort in place (so leaves original unchan­ged), returns a new list