My Python Cheatsheet
Lists
Dictionaries
Modules
- Packages (e.g. pyspark) contain modules (e.g. pyspark.sql), which in turn define classes, functions, etc. (e.g. pyspark.sql.HiveContext(SparkContext)).
- Load a package or a module by issuing
import numpy
. You can then access its functions bynumpy.array([2,4,6])
. If you want to type less, you can importnumpy
asnp
, which allows you to callnp.array([2,4,6])
. - You can hand-pick single functions with
from numpy import array
and can then directly callarray([2,4,6])
, but this is discouraged as it could lead to namespace clashes. - A possibility (although not recommended) is to use
from numpy import *
. This imports all definitions in numpy directly. Again, not recommended.
Functional programming
The following two versions are equivalent: