Python 练习范例 42
学习使用 auto 定义变量的用法
没有 auto 关键字,使用变量作用域来举例吧
#!/usr/bin/python # -*- coding: UTF-8 -*- num = 2 def autofunc(): num = 1 print 'internal block num = %d' % num num += 1 for i in range(3): print 'The num = %d' % num num += 1 autofunc()
以上 Python 代码输出结果如下
The num = 2 internal block num = 1 The num = 3 internal block num = 1 The num = 4 internal block num = 1