Python 全局变量可以在局部作用域中使用

例子:def spam(): print(egg) egg =42 spam() print(egg) 在def spam()自定义函数中,没有定义egg的值,在全局域中定义了一个egg=42 ,则局部作用域使用全局域中的值,所以会输出:42 42

- 阅读全文 -

Python局部作用域不能使用其它局部作用域的变量

例子:def spam(): egg = 99 bacon() print(egg) def bacon(): ham =101 egg = 0 spam() 例子中只输出了spam()的egg,而spam()中引用的bacon()没有输出结果,所以egg = 0属于另一个作用域中的赋值,使用过后就销毁了,如果在结尾在加上print(egg),也会出现报错

- 阅读全文 -

Python return返回值

例:import random def getAn(answer): if answer == 1: return 'one' elif answer == 2: return 'tow' elif answer == 3: return 'three' elif answer == 4: retur

- 阅读全文 -

Python def函数及参数

自定义函数例一:def hello(): print("K") print("J") print("I") print('\n') hello() hello() hello() 例二:def hello(name): print('hello '+name) hello("Alic

- 阅读全文 -

Python sys.exit语句提前结束

例:import syswhile True:print("Type exit to exit.") res = input("请输入:") if res == "exit": sys.exit() print("You type " + res +'.')

- 阅读全文 -

Python 模块导入

例一:导入随机数模块,显示5次1-10中的随机数import random for i in range(1,6): print(random.randint(1,10))

- 阅读全文 -

最新文章

最近回复

  • eric: 我自己重置的时候截图的 你可以尝试
  • 123: 写的不详细,操作失败
  • iStoreOS作为旁路由安装wireguard: [...]软件包参考教程Eric’s Blog 【L...
  • eric: 爱意随风起,风止意难平
  • Eric.Qiu: 生老病死三千疾,唯有相思不可医
  • v2ray节点: 感谢分享
  • 免费梯子: 友链申请 网站名称:免费梯子 网站链接:https://clas...
  • clash for windows教程: 感谢博主分享!
  • eric: 那一堆软件装了没有呢,还有新建网络接口了吗
  • zhao: 你好,我的istore os接口怎么没有wireguard这是什...

其它

友链