Classes are objects"In Python, everything is an object"That applies for classes as well which means that classes:can be created at runtimepassed as paramtersreturned from funtionsassigned to variablesBuiltin type functionThe simplest way to create class dynamically is to use type :def create_klass(name, **kwattrs): return type(name, (object,), dict(**kwattrs))>> my_test_klass = create_klass('MyTestClass',
Monday, December 21, 2015
Tuesday, December 15, 2015
Python : filter(), map() and reduce()
filter(), map() and reduce() tools are functional programming methods that can beapplied to iterable objects.filter(<function>, <object>)Iterates on object and returns the list of elements from <object> for which <function> returned True.Usually, lambda functions are used for <function>. A lambda function returns True when the condition is met (example :
Subscribe to:
Posts (Atom)