In Python, there are also global variables and local variables, but as far as I know, if a variable defined in the if is a global variable that falls down, there is also a function definition and return in Python, usually defining a function:
def function name (parameter 1, parameter 2, ...) ):
function body
return x
Of course, no arguments are allowed, and if you do not write return, the default return is NULL, and the value of the global variable cannot be modified within the function, and if you want to assign a value to a global variable outside the function, you use the global statement to indicate that the variable is a global variable. Otherwise, it will go wrong. However, if you do not need to reassign a global variable, you may not use the global statement, but you can tell the person reading the code after using the global statement, which is already stated in the global variable.
# !/usr/bin/env Python 3.6 " -*-Coding:-utf8--*- " Num=10def changnum (): global num print( num) num=100 print(num) return numPrint (Changnum ())
The path to learning in Python--05 basic articles