题目:学习使用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()
# -*- 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()
以上实例输出结果为:
The num = 2internal block num = 1The num = 3internal block num = 1The num = 4internal block num = 1