into run by your code No compiling into machine code! Only syntax errors caught at compile time not the OS if Python code and machine instrs. had a baby
dotted segment takes time! Your code runs slower than a C++ executable! Disclaimer: This is very simplified, but it gives you a general idea of why Python code is slower than C++. C++ executables can be directly run by your CPU; Python bytecode can't.
• it has member functions • you can pass it around / assign it to something In Python, pretty much everything has that last property, and most objects have the first two as well.
= x >>> x += ' is cool' >>> x 'nick' string object y 'nick is cool' string object x and y (and all other variable names) are essentially pointers to objects.
or immutable. This property has huge implications for the behavior of a program! Mutable: lists, dicts, sets, user classes Immutable: strings, numbers, tuples
L def addTo(L, s): L.append(s) >>> x = [] >>> addTo(x, 'sup') >>> print x ['sup'] >>> Lists are mutable! list with contents [ 'sup' ] This works sort of like pass-by- reference in C++. When you pass in a mutable object and change it, you see the changes reflected in the caller. x
identities of its operands. if x is y: is equivalent to if id(x) == id(y): Use this to check if two variables point to the same object, or to check if an object is None.
each number in the sequence 2, 4, 6, 8, ... forever and ever. How do you do this? Attempt 1: for i in range(0, infinity, 2): do_something(i) if condition: break
keyword: def even_numbers(): i = 0 while True: yield i i += 2 >>> n = even_numbers() >>> n.next() 0 >>> n.next() 2 Generators are like functions that remember their state
3-letter words: PIP and GIT Install stuff from the Python Package Index (PyPI) Get other people's open source code Do you really want to write code to parse JSON strings?
$ cd ~/code/myproject $ virtualenv env ... <output stuff> ... $ env/bin/pip install requests $ env/bin/python myscript.py Creates a dir named env with its own python / pip executables Only installs it in the virtual environment env/