Python is simple and elegant, the library is rich and powerful, especially in the field of data analysis, has an important position.
Here are some of the important, easy-to-forget knowledge points I learned
How is python doing memory management?
First of all, Python creates an object that is a ternary group (identity, type, value). When we invoke an object, it is generally passed by reference.
is passed by value if necessary. (No new object by reference, new object by value)
1. Reference counting mechanism
When an object is created, each time a name is assigned or the object is placed in a container, the object's reference count increases;
Every del a name or reference is out of scope or is re-assigned, and the reference count of the object is reduced.
When the reference count is zeroed, it is disposed of by the garbage collection mechanism.
2. Memory pool mechanism
Python provides a garbage collection mechanism for memory, but it puts unused memory into the memory pool instead of returning it to the operating system.
All objects less than 256 bytes in Python Use the allocator implemented by Pymalloc, while large objects use the system malloc.
The different types of objects, such as integers, floating-point numbers, and lists, have their own private pools of memory that are not shared between objects.
Second, try...except...except ... [Else ...] [Finally ...]
Python first attempts to execute a try-under statement:
If the exception, and a number of except to match the exception, and execute the matching except statement, if all do not match the exception will be passed to the top-level try, and finally execute the fanally statement;
If there is no exception, the Else statement is executed and the fanally statement is executed last.
The following sample code, you can try to run under, to help memory
1 defexcepttest ():2 Try:3 Print 'doing some work, and maybe exception 'll be raised'4 RaiseIndexerror ('Index Error')5 #print ' After exception raise '6 #return 07 8 exceptKeyerror, E:9 Print 'In Keyerror except'Ten Printe One #return 1 A exceptIndexerror, E: - Print 'In Indexerror except' - Printe the #return 2 - exceptZerodivisionerror, E: - Print 'In zerodivisionerror' - Printe + #return 3 - Else: + Print 'no exception' A return4 at finally: - Print 'In finally' - #return 5 - -ResultCode =excepttest () - PrintResultCode
Python key points of knowledge (constantly updated)