by Xiaokang Zhang | Jun 18, 2018 | Computer Science
Per history of python blog, everything in python are first class objects, that means all objects that could be named in the language (e.g., integers, strings, functions, classes, modules, methods, etc.) to have equal status. Th:at is, they can be assigned to...
by Xiaokang Zhang | Jun 16, 2018 | Computer Science
Iteration Python support iteration, for example, iterating over a list: for elem in [1, 2, 3]: print elem Iterating over a dict: for key in {‘Google’: ‘G’, ‘Yahoo’: ‘Y’, ‘Microsoft’: ‘M’}: print...
by Xiaokang Zhang | Jun 12, 2018 | Computer Science
Python supports context management. Which often used when handling resources, for example, file, network connection. With statement helps make sure the resources are cleaned up or released. There are two major functions for context management: __enter__ and __exit__....
by Xiaokang Zhang | Jun 9, 2018 | Computer Science
The following is an example of python closure. def outer_function(outter_arg): closure_var = outter_arg def inner_function(inner_arg): print(“{} {}”.format(closure_var, inner_arg)) return inner_function # Usage of a python closure closure_func =...