Control Structures
Boolean Logic
|
|
|
|
Operator Precedence
List
|
|
|
|
Functions
函数可以直接调用!
|
|
|
|
Exceptions
ImportError : an import fails;
IndexError : a list is indexed with an out-of-range number;
NameError : an unknown variable is used;
SyntaxError : the code can’t be parsed propertly;
TypeError : a function is called on a value of an inappropriate value.
Exception Handing
|
|
|
|
OR
|
|
|
|
|
|
|
|
Functional Programming
Lambda
lambad 三种用法:
|
|
|
|
|
|
|
|
map
The function map takes a function and an iterable as arguments, and returns a new iterable with the function applied to each argument.
|
|
|
|
Filter
The function filter filters an iterable by removig iterms that don’t match a predicate
|
|
|
|
generators(yield)
Generators ate a type of iterable, like lists or tuples.
They can be created using functions and the yield statement.
Using generatoers results in improved performance, which is the result of the lazy (on demand) generation of values, which translates to lower memory usage.
|
|
|
|
|
|
|
|
Decorators( @ )
装饰函数个人理解,相当于定义一个嵌套函数,作为主函数,@后面加拓展函数,调用只需拓展函数名即可。
Thisideal when you need to extend the functionality of functionality of functions that you don’t want to modify.
原理:
|
|
Using @ (decorate):
|
|
result:
|
|
Object-Oriented Programming (OOP)
Class
The class describes what the object will be, but is separate from the object itself .
You can use the same class as a buleprint for creating multiple different objects.
开头字母大写!This is a good hobby!
|
|
init : This is called when an instance (object) of the class is created , using the class name as a function.
Methods
All methods must have self as their first parameter
|
|
|
|
Class attributes
This is applies whrn you call an undefined
|
|
|
|
声明:
欢迎转载,转载时请注明出处
JacobYRJ