Functions and procedures
#-*-coding:utf-8-*-#functiondeffunc1 ():"""testing1""" Print('In the func1') return0#procedure is a function that does not return a valuedefFunc2 ():"""testing2""" Print('In the Func2') x=func1 () y=Func2 ()Print('From func1 return is%s'%x)Print('From Func2 return is%s'%y
The above code runs the result
inch The func1 inch The Func2 from return is 0 from return is None
Function call Example one:
# -*-coding:utf-8-*- def Test (x, y ): Print ('x=%d'%x) Print ('y=%d'%y) Test (y=2,x=1) # keyword invocation, independent of formal parameter order
The above code runs the result
X=1y=2
Example two:
# -*-coding:utf-8-*- def Test (x, y ): Print ('x=%d'%x) Print ('y=%d'%y) Test (+) # positional parameter invocation, actual participation in the position one by one corresponding to the formal parameter
The above code runs the result
X=1y=2
Example three:
# -*-coding:utf-8-*- def Test (x, y , z): Print ('x=%d'%x) Print ('y=%d'%y) Test (3,z=2,y=6) # keyword to be placed after the position parameter
The above code runs the result:
X=3y=6
Python Basics Four