Around a language, learn its cultural essence, allowing you to become a better programmer. If you have not read Python Zen (Zen of Python), then open a command prompt, enter the Python import this, list each item you can find the corresponding examples Air Max 2012 Black Red White here. (Credit: itswater) attracted my attention is one: elegant than ugly (Beautiful is better than ugly) Look at the following example: list function with a numeric parameter whose function is to return parameters can be separated from the odd write: # - ʱ?? -------------------- halve_evens_only = lambda nums: map (lambda i: i / 2, \\ filter (lambda i: not i% 2, nums)) # - ʱ?? -------------------- def halve_evens_only (nums): return [i / 2 for i in nums if not i% 2] those very simple things to remember in Python swap two variables: a, b = Nike Air Max b, a parameter in the slicing operation steps, such as: a = [1,2,3,4,5] \u0026 gt; \u0026 gt; \u0026 gt; a [:: 2] # In 2 step increments iteration 626969-030 Air Jordan 4 Retro Fear Pack Nike Kids Sneakers entire list Object [1,3,5] a special case `x [:: - 1]` is used to reverse the practical grammar x. \u0026 Gt; \u0026 gt; \u0026 gt; a [:: - 1] [5,4,3,2,1] Do not use mutable objects as default parameter values (Do not use mutable as defaults) def function (x, l = [ ]): # Do not be so dry def function (x, l = None): # A better approach if l is None: l = [] instead of using iteritems itemsiteriterms using generators, so when a lot of iterative sequence is this method better d = {1: \u0026 quot; 1 \u0026 quot ;, Air Jordan Outlet 2: \u0026 quot; 2 \u0026 quot ;, 3: \u0026 quot; 3 \u0026 quot;} for key, val in d.items () # call items 2015 Nike Free 5.0 (can build a complete) after list objects for key, val in d.iteritems () # only once per request iteration only generate a relationship and a range of scenarios occasion xrange similar. Use Air Max 2011 Womens Wine Red White Grey isinstance instead type do not do this: if type (s) == type (\u0026 quot; \u0026 quot;): ... if type (seq) == list or \\ type (seq) == tuple: ... should be Thus: if isinstance (s, basestring): ... if isinstance (seq, (list, tuple)): ... as to why doing so, 653642-400 Blue Orange Lebron James Mens Basketball Shoes Nike Zoom Soldier VIII 8 see here: http: //stackoverflow.com/a/1549854/504262 need Note that this use basestring instead of str because you may use a unicode object is to check whether the SALOMON string, for New Nike Free 5.0 V4 Shoes Grey Black example: \u0026 gt; \u0026 gt; \u0026 gt; a = u'aaaa '\u0026 gt; \u0026 gt; \u0026 gt; print isinstance (a, basestring ) True \u0026 gt; \u0026 gt; \u0026 gt; print isinstance (a, str) False because there are two types of string str and unicode object 3.0 version of the following in Python | basestring / \\ str unicode learn a variety of collections (learn the various collections) There are a variety of containers python data type, select python built-in container under certain circumstances, such as: list and dict. More generally use as follows: freqs = {} for c in \u0026 quot; abracadabra \u0026 quot ;: try: freqs [c] + = 1 except: freqs [c] = 1 A better scheme is as follows: freqs = {} for c in \u0026 quot; abracadabra \u0026 quot ;: freqs [c] = freqs.get (c, 0) + 1 a better choice collection type defautdict: from collections import defaultdictfreqs = defaultdict (int) for c Air Max 2012 Blue Grey White in \u0026 quot; abracadabra \u0026 quot ;: freqs [c] + = 1 Other collections namedtuple () # create factory functions deque tuple subclass of # similar list of containers with the Air Max 2012 Blue Silver White specified domain, quickly append and delete both ends Counter # statistics hash table sequence dict subclass OrderedDict # recording entity add sequence dict subclass defaultdict # call the factory method provides default values for the key of dict subclass when creating Python-magic method: Behavior __eq __ (self, other) # define equality operation ==. __ne __ (self, other) # define unequal operation behavior,! =. __lt __ (self, Authentic Mens Basketball Shoes All Red Nike KD 7 Factory Outlet other) # define the less than operator behavior, \u0026 lt ;. __gt __ (self, other) # define no more than the behavior of the operation, \u0026 gt ;. __le __ (self, other) # define less behavioral operation, \u0026 lt;. = __ge __ (self, other) # define more than the behavior of equals operation, \u0026 gt; = condition assignment x = 3 if (y == 1) else 2. Please expressions just like them: if y is equal to 1 to put 3 assigned to x, otherwise the 2 assigned to x, of course, can also be used if you have an Nike Air Jordan 5 Women assignment chain conditions more complex conditions of words. x = 3 if (y == 1) else 2 if (y == -1) else 1 However, to a certain point, it's a bit much. Remember that you can use if-else in any expression such as: (func1 if y == 1 else func2) (arg1, arg2) func1 will be called if y equals 1, then conversely func2 is called. In both cases, arg1 and arg2 Both parameters are included with the corresponding function. Similarly, the following expression is New Nike Free 5.0 V4 Shoes Black Red also a right x = (class1 if y == 1 else class2) (arg1, arg2) class1 and class2 are two classes at the right time when it is necessary to use the Ellipsis create a class, you can use __getitem__, let Nike Blazers Low your class work like a dictionary, for example, take the following class: class MyClass (object): def __init __ (self, a, b, c, d): self.a, self.b, self. c, self.d = a, b, c, d def __getitem __ (self, item): return getattr (self, item) x = MyClass (10, 12, 22, 14) because __getitem__, you will be able to pass object x x ['a'] Gets a value that should be acknowledged. This object is typically used to inherit Python slice (slicing) (http://docs.python.org/library/stdtypes.html#bltin-ellipsis-object), if you add the following statement: def __getitem __ (self, item): if item is Ellipsis: return [self.a, self.b, self.c, self.d] else: return getattr (self, item) we can use x [...] acquired sequence contains all items \u0026 gt; \u0026 gt; \u0026 gt; x = MyClass (11, 34, 23, 12) \u0026 gt; \u0026 gt; \u0026 gt; x [...] [11, 34, 23, 12]Python programming some of the things to note