标签:位置 域名 容器类 oba while pre one def div
初次编辑2017年10月25日,星期三
引用:Alex
def f1():
x = 1
print(‘----->f1 ‘,x)
def f2():
x = 2
print(‘---->f2 ‘,x)
def f3():
x = 3
print(‘--->f3 ‘,x)
f3()
f2()
f1() >>>----->f1 1;---->f2 2;--->f3 3
def foo():
print(‘foo‘)
print(foo)
f = foo
print(f)
def foo():
print(‘foo‘)
def bar(func): >>><function foo at 0x00000000003E3F28>;foo
print(func)
func()
bar(foo)
def foo():
print(‘foo‘)
def bar(func):
print(func)
return func
f = bar(foo)
print(f)
def add():
print(‘==========function add‘)
def delete():
print(‘==========function delete‘)
def search():
print(‘==========function search‘)
def change():
print(‘==========function change‘)
def tell_msg():
msg = ‘‘‘
delete:删除
add:添加
search:查询
change:更改
‘‘‘
print(msg)
cmd_list = {
‘add‘:add,
‘delete‘:delete,
‘search‘:search,
‘change‘:change
}
while True:
tell_msg()
choice = input(‘please input your choice: ‘).strip()
cmd_list[choice]()
x =1
def f1():
x = 1000
def f2():
print(x)
return f2
f = f1()
f()
print(f.__closure__[0])
print(f.__closure__[0].cell_contents)
>>><1000
>>><cell at 0x0000000002177498: int object at 0x0000000001DC9EF0>
>>>1000
from urllib.request import urlopen
def f1(url):
def f2():
print(urlopen(url).read())
return f2
baidu = f1(‘http://www.baidu.com‘) #爬网页
baidu()
标签:位置 域名 容器类 oba while pre one def div
原文地址:http://www.cnblogs.com/sama/p/7825399.html