Jesse's Blog » 2008年 » 5月
Notes_5_on <Learning Python>
Jesse 发表于 2008-05-31 22:31:27
Part.IV Functions
1.
A iteration contexts, including for loops, map calls and list comprehensions, are in turn designed to automatically call the iter function to see if the (iterator) protocol is supported. P236
2.
Gotchas: local names are detected statically. P239
x = 99
def foo():
print x
def bar():
print x
x = 88 #==> UnboundLocalError: local variable 'x'
# referenced before assignment
3.
bound:
(1).附着的,粘附的. UnboundLocalError
(2).be bound up with, 有赖于,与...有关系. Generator functions are bound up with the notion of iterator protocols in Python.P234
4.
Python saves one object per default argument, attached to the function itself. P241.
E.g.
def saver(x = []):
x.append(1)
print x
saver([2]) ==> [2, 1]
saver() ==> [1]
saver() ==> [1, 1]
saver() ==> [1, 1, 1]
1.
A iteration contexts, including for loops, map calls and list comprehensions, are in turn designed to automatically call the iter function to see if the (iterator) protocol is supported. P236
2.
Gotchas: local names are detected statically. P239
x = 99
def foo():
print x
def bar():
print x
x = 88 #==> UnboundLocalError: local variable 'x'
# referenced before assignment
3.
bound:
(1).附着的,粘附的. UnboundLocalError
(2).be bound up with, 有赖于,与...有关系. Generator functions are bound up with the notion of iterator protocols in Python.P234
4.
Python saves one object per default argument, attached to the function itself. P241.
E.g.
def saver(x = []):
x.append(1)
print x
saver([2]) ==> [2, 1]
saver() ==> [1]
saver() ==> [1, 1]
saver() ==> [1, 1, 1]
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
