标签:
# 在 Java/C+ 世界里没法打印 name # 但在 Python/ JavaScript 世界里可以打印 name >>> if 1 == 1: ... name = ‘Janice‘ ... >>> print(name) Janice
>>> for i in range(10): ... name = i ... >>> print(name) 9
>>> del name >>> def func(): ... name = ‘Janice‘ ... >>> print(name) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name ‘name‘ is not defined
>>> name = ‘alex‘ # 这是 f1()是作用域,它是一个内部的作用域 >>> def f1(): ... print(name) ... # 这是 f2()是作用域 >>> def f2(): ... name = ‘eric‘ ... f1() ... >>> f2() alex
>>> name = ‘alex‘ # 这是 f1()是作用域,它是一个内部的作用域 >>> def f1(): ... print(name) ... # 这是 f2()是作用域 >>> def f2(): ... name = ‘eric‘ ... return f1 ... >>> ret = f2() >>> ret() # 这相当于运行 f1() alex
# 它会执行一个 For 循环,然后把每一个元素都加1,最后生成一个列表 li = [x+1 for x in range(10) if x > 6] print(li)
>>> li2 = [lambda :x for x in range(10)] >>> ret = li2[0]() >>> print(ret) 9
>>> li = [] >>> for i in range(10): ... def f1(x=i): ... return x ... ... li.append(f1) ... >>> print(li[0]()) 0 >>> print(li[1]()) 1 >>> print(li[2]()) 2
用到了IO多路復用
多线程、多進層、協程
day10作业
标签:
原文地址:http://www.cnblogs.com/jcchoiling/p/5937538.html