Hidden features of Python
pythontricksadvanced-featuresstackoverflow
Abstraction: Lesser-known Python language features and hidden tricks
Key points:
- Chaining comparison operators:
1 < x < 10is valid Python syntax - Decorators, descriptors, and
__missing__for advanced object customization - In-place value swapping without temp variable:
a, b = b, a - Generator expressions vs list comprehensions;
for/elseclause executes when loop completes withoutbreak - Mutable default argument danger: default args are evaluated once at function definition, not each call
itertools,withstatement, and ternary expressions (x if cond else y) among top hidden features
Connections: Python · Python Idioms · Metaprogramming
Source: http://stackoverflow.com/questions/101268/hidden-features-of-python?lq=1