That should know about class in Python
September 14, 2008
__init__ methods are optional, but when you define one, you must remember to explicitly call the ancestor’s __init__ method (if it defines one). This is more generally true: whenever a descendant wants to extend the behavior of the ancestor, the descendant method must explicitly call the ancestor method at the proper time, with the proper arguments.
About lambda
September 14, 2008
So-called lambda functions can be used anywhere a function is required as in-line function in C++.
def f(x):
return x*2
f(4)
We can replace this function by:
g = lambda x: x*2
g(4)
Same!!!!!!
Python most important functions
September 11, 2008
- type
- str
- dir
The type Function
- The type function returns the datatype of any arbitrary object.
- type(1) — > <type ‘int’>.
The str Function
- The str coerces data into a string.
- Every datatype can be coerced into a string.
- str(1) — > ’1′.
Introducing dir
- dir returns a list of the attributes and methods of any object: modules, functions, strings, lists, dictionaries… pretty much anything.
Introducing callable
- the callable function takes any object and returns True if the object can be called, or False otherwise.
Two special command.
import __builtin__
dir(__builtin__)