Python 複習筆記,紀錄比較容易忘記的重點。
- You create a list comprehension with brackets
[], including an expression to evaluate for each element in an iterable. [ i for i in ragne(4) ] --> [1, 2, 3]
- 前面有雙底線的變數,就是 Private 變數。 two underscores (
__) in front of it.
Lambda Expressions
You can use lambda expressions to create anonymous functions. That is, functions that don’t have a name. They are helpful for creating quick functions that aren’t needed later in your code. This can be especially useful for higher order functions, or functions that take in other functions as arguments.
With a lambda expression, this function:
def multiply(x, y):
return x * y
can be reduced to:
multiply = lambda x, y: x * y

留言
發佈留言