Hidden features of Python -
what lesser-known useful features of python programming language?
- try limit answers python core.
- one feature per answer.
- give example , short description of feature, not link documentation.
- label feature using title first line.
quick links answers:
- argument unpacking
- braces
- chaining comparison operators
- decorators
- default argument gotchas / dangers of mutable default arguments
- descriptors
- dictionary default
.getvalue - docstring tests
- ellipsis slicing syntax
- enumeration
- for/else
- function iter() argument
- generator expressions
import this- in place value swapping
- list stepping
__missing__items- multi-line regex
- named string formatting
- nested list/generator comprehensions
- new types @ runtime
.pthfiles- rot13 encoding
- regex debugging
- sending generators
- tab completion in interactive interpreter
- ternary expression
try/except/else- unpacking+
print()function withstatement
chaining comparison operators:
>>> x = 5 >>> 1 < x < 10 true >>> 10 < x < 20 false >>> x < 10 < x*10 < 100 true >>> 10 > x <= 9 true >>> 5 == x > 4 true in case you're thinking it's doing 1 < x, comes out true, , comparing true < 10, true, no, that's not happens (see last example.) it's translating 1 < x , x < 10, , x < 10 , 10 < x * 10 , x*10 < 100, less typing , each term evaluated once.
Comments
Post a Comment