Stopping of execution of boolean operation if the truth value of expression has been determined already.
Practice Short Circuiting
>>> True and False False >>> True or False and False True >>> 2 or not 2 2 >>> "Be" and 1 and 2 and 3 and 4 and 5 5 >>> 3 or 1/0 and 5 3 # expression short circuits at 3 or and evaluates to 3 without evaluating 1/0 and 5 >>> 0 or 0 and 1/0 0 >>> 0 or 5 and 1/0 Error
Variables
Variable
A variable is a named memory location (box) that contains a value (in the box) and can be used in expressions.
Assignment
Execution Rule
Evaluate all expressions to the right of = from left to right.
Bind all names to the left of = to those resulting values.
Example
>>> a, b = 0, 1 >>> a, b = b, a >>> a, b (1, 0)
Do not name your variables as built-in function names
E.g. sum, max, etc.
Functions
A function takes as input one or more arguments, computes a new value, a string or a number, and returns the value, so that it can be assigned to a variable or output.
Parameters vs. Arguments
The arguments are the data you pass intoo the function’s parameters.
Control Flow
Reading the function definition without executing
Seeing a “call” to the function, jumping up to the start of the function and executing
Returning back to the place in the program that called the function and continuing.