Python includes exercises 42
Topic: Learn to use Use auto-defined variables.
Program Analysis: No auto keyword, use variable scope exemplified it.
Source Code:
#!/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()
The above example output is:
The num = 2 internal block num = 1 The num = 3 internal block num = 1 The num = 4 internal block num = 1