by Chee Yee Lim
Posted on 2021-04-17
Collection of notes on key points for Python
lambdais a keyword in Python that creates an anonymous function.
lambdacan have any number of parameters but only one expression.
**kwargsfor function arguments
*argsis used when we don't know how many arguments will be passed to a function. The function will access the parameters by positions.
**kwargsis used when we don't know how many keyword arguments will be passed to a function. The function will access the parameters by argument keywords.
selfis an instance of a class.
E.g. ``` mystr = "banana" myit = iter(mystr)
- A for loop is typically used to iterate through an iterable object.
- Functions that return an iterable set of items are called generators.
- Range and xrange are exactly the same in terms of functionality.
- The only difference is range returns a list object while xrange returns an xrange object.
- xrange object is a generator, which saves memory by not materialising the whole array of values in the beginning.
x = 1 y = x y = 2 print(x) # it will be 1
x = [1,2] y = x y = 9 print(x) # it will be [1,9]