The def function in Python.

Don't talk nonsense, just start! ! !
def fun():
    a =10
    print(a)
fun()    

Output result:
Insert picture description here
def is to define a new function (I defined fun()), and then type fun() at the end, otherwise the output result is 0, or type fun() on the output result.

def fun():
    a =10
    print(a)
    return a + 100
print(fun())

Output result: the
Insert picture description here
first output is the value of a, and the second output is the value within the function (from def to return).
Note: The variable (a) in the defined function is a local variable and cannot be output directly in subsequent processes. Local variables will be introduced later.

Guess you like

Origin blog.csdn.net/Kinght_123/article/details/108908126