摘要:
1. Object Representations Every object-oriented language has at least one standard way of getting a string representation from any object. Python has 阅读全文
摘要:
1. Varaibles Are Labels, Not Boxes. Python varaibles are like reference variables in Java, so it's better to think of them as labels attached to objec 阅读全文
摘要:
Function decorators let us "mark" functions in the source code to enhance their behavior in some way. This is powful stuff, but mastering it requires 阅读全文
摘要:
Although design patterns are language-independent, that does not mean every pattern applies to every language. If we assumed procedural languages, we 阅读全文
摘要:
The "First-Class object" in Python: Created at runtime Assigned to a variable or element in a data structure Pass as an augument to a function Return 阅读全文
摘要:
1. Handling missing keys with setdefault import sys import re WORD_RE = re.compile('\w+') index = {} print(sys.argv) # Example 3-2 with open(sys.argv[ 阅读全文
摘要:
1. Managing Ordered Sequences with bisect The bisect module offers two main functions bisect and insort that use the binary serach algorithm to quickl 阅读全文
摘要:
列表推导式总共有两种形式: ① [x for x in data if condition] # 此处if主要起条件判断作用,data数据中只有满足if条件的才会被留下,最后统一生成为一个数据列表 ② [exp1 if condition else exp2 for x in data] # 此处i 阅读全文