Python Exercise Example 42
**Problem:** Learn how to use auto to define variables.
**Program analysis:** There is no auto keyword; let's use variable scope as an example.
Program source code:
Example
#!/usr/bin/python
-- coding: UTF-8 --
num
=
2
def
autofunc
(
)
:
num
=
1
(
'internal block num = %d'
% num
)
num +
=
1
for
i
in
range
(
3
)
:
(
'The num = %d'
% num
)
num +
=
1
autofunc
(
)
The output of the above example is:
The num = 2
internal block num = 1
The num = 3
internal block num = 1
The num = 4
internal block num = 1
Python 100 Examples