type()
To get the type of any object use type().
x = 4
print(type(x))
Variables and parameters are local
Variables and parameters inside a function exist only inside that function.
Modules
A module is a file containing python commands such as the math module or one created by yourself.
import math
Expressions and Statements
- Expression — combination of values and operations that create a new value (return a value)
- Statement — performs a task with no return value e.g. controlling the flow of the program
Expressions can be printed whereas statements cannot.
x+5 #expression y=x+5 #statement
Recursion
Recursion is when a function calls itself, e.g.
def countdown(n): if n <= 0: print(' Blastoff!' ) else: print(n) countdown(n-1)
Infinite recursion is generally not a good idea
def recurse(): recurse()
Python will report an error message when the maximum recursion depth is reached:
>>>RuntimeError: Maximum recursion depth exceeded
list vs tuple
keywords vs built-in functions
f strings