1.3 - Basics of Programming

Ha Khanh Nguyen - hknguyen

In this lecture, we will discuss:


1. Indentations, not braces


2. Everything is an object


3. Comments in Python


4. Variables and arguments passing


5. Dynamic references, strong types


6. Attributes and methods


7. Imports

Or


8. Binary operators and comparisons

Operation Description
a + b Add a and b
a - b Substract b from a
a * b Multiply a by b
a / b Divide a by b
a // b Floor-divide a by b, dropping any fractional remainder
a ** b Raise a to the b power
a & b True if both a and b are True; for integers, take the bitwise AND
`a b` True if either a or b is True; for integers, take the bitwise OR
a ^ b True if a is True or b is True, BUT NOT BOTH; for integers, take the bitwise EXCLUSIVE-OR
a == b True if a equals b
a != b True if a is not equal to b
a <= b, a < b True if a is less than (less than or equal) to b
a >= b, a > b True if a is greater than (greater than or equal) to b
a is b True if a and b reference the same Python object
a is not b True if a and be references different Python objects

9. Mutable and immutable objects


This lecture note is modified from Chapter 2 of Wes McKinney's Python for Data Analysis 2nd Ed.