4.1 python function of Lego
There are three parts python functions, objects, and modules may simplify the procedure
1. Create a function
def myfunction():
def myfunction():
print("this is my first function\nI am excited\nThank you!!!")
2. call function
1) function name ()
myfunction()
When a function call is looking forward function name, if part of the Wang Qianmian not find, you can not perform the
mechanisms function and circulation is actually similar principle, but adds a parameter
2) Parameters
def myfuc1(name):
print(name + ' I love weivid')
myfuc1('nihao')
def add(num1,num2):
result = num1 +num2
print(result)
add(1,2) #执行1+2 ,结果为3
3) return function return value
In return function using
def add(num1,num2):
return(num1 + num2)
print(add(4,2)) #执行完4+2时,返回值作为print函数的参数,打印6