One, the object
1. The object type is divided into:
A. Variable (mutable) objects include, list, dictionary (dictionary);
B. Immutable (immutable) objects include, tuple (tuple), numeric value (number), string;
2. Comparison of objects:
A. Identity comparison: Used to determine whether the same object, for example: ID ();
B. Type comparison: Used to determine whether the same type, for example: type ();
C. Value comparison: The value is the same, the direct equivalence comparison;
3. Callable Objects:
A. How to determine if callable, syntax: callable ();
B. The callable object calls the method, class, function in the object;
For example:
In [2]: Def printname (): ...: print "Hello" ...: in [4]: Callable (Printname) out[4]: True
Two, in situ modification
1. Modification of the list in situ
A.list.sort () in situ order;
B.list.reverse in reverse order;
2. Dictionaries
Dict.iteritems () returns the generator, traversing each element;
For example:
in [+]: D1 = {' x ': 1, ' Y ': 2} in [+]: I1 = D1.iteritems () in [All]: I1.next () out[15]: (' Y ', 2) in [+]: I1.next () out[16]: (' X ', 1) in []: I1.next ()---------------------------------------------------------------------------stopiteration Traceback (mostrecent) <ipython-input-17-be7912f76fe0> in <module> ()----> 1 i1 . Next () Stopiteration:
Third, how to get object use Help
1. Get the properties and methods that the object supports:
For example: Dir (d1)
2. Specific use of a method to help:
Example: Help (List.pop)
3. Get the document string for the callable object:
Example: print.obj.__doc__
This article is from "Jessen Liu's blog," Please make sure to keep this source http://zkhylt.blog.51cto.com/3638719/1706669
Callable objects, list and dictionary in situ modification features 16