Hidden features of Python
What are the lesser-known but useful features of the Python programming language?
Quick links to answers:
.get
value import this
__missing__
items .pth
files try/except/else
print()
function with
statement Metaclasses
of course :-) What is a metaclass in Python?
I personally love the 3 different quotes
str = "I'm a string 'but still I can use quotes' inside myself!"
str = """ For some messy multi line strings.
Such as
<html>
<head> ... </head>"""
Also cool: not having to escape regular expressions, avoiding horrible backslash salad by using raw strings :
str2 = r"n"
print str2
>> n
Generators
I think that a lot of beginning Python developers pass over generators without really grasping what they're for or getting any sense of their power. It wasn't until I read David M. Beazley's PyCon presentation on generators (it's available here) that I realized how useful (essential, really) they are. That presentation illuminated what was for me an entirely new way of programming, and I recommend it to anyone who doesn't have a deep understanding of generators.
链接地址: http://www.djcxy.com/p/7414.html上一篇: 整数空值
下一篇: Python的隐藏功能