| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 
Type "copyright", "credits" or "license()" for more information. 
>>> count=5 
>>> def myFun(): 
        count=22 
        print(count) 
 
         
>>> myFun() 
22 
>>> print(count) 
5 
>>> def myFun(): 
        global count 
        count=22 
        print(count) 
 
         
>>> myFun() 
22 
>>> print(count) 
22 
>>> def FunX(x): 
        def funY(y): 
                return x*y 
        return funY 
 
>>> def funX(x): 
        def funY(y): 
                return x*y 
        return funY 
 
>>> funX(2) 
<function funX.<locals>.funY at 0x000000F39D8D9D90> 
>>> funY(3) 
Traceback (most recent call last): 
  File "<pyshell#19>", line 1, in <module> 
    funY(3) 
NameError: name 'funY' is not defined 
>>> funX(2)(3) 
6 
>>> def funX(x): 
        def funY(y): 
                return x*y 
 
         
>>> funX(2)(3) 
Traceback (most recent call last): 
  File "<pyshell#23>", line 1, in <module> 
    funX(2)(3) 
TypeError: 'NoneType' object is not callable 
>>>  |   
 
 
 
 |