function return value
#coding: Utf-8
def f (x, Y):
Print x+y/*x+y is calculated x+y If "x+y" is directly output x+y*/
F (97,98)
D:\Python installation program \python.exe c:/users/Huan/pycharmprojects/untitled/ll.py
195
Process finished with exit code 0
#coding: Utf-8
def f (x, Y):
Print "Welcome"
Print X+y
F (2,3)
Z=f (3,4)
Print Z
D:\Python installation program \python.exe c:/users/Huan/pycharmprojects/untitled/ll.py
Welcome
5
Welcome
7
None
Process finished with exit code 0
#coding: Utf-8
def f ():
return "Hello"
z= f ()/* must return a specified value after the function is called, otherwise it cannot output */
Print Z
D:\Python installation program \python.exe c:/users/Huan/pycharmprojects/untitled/ll.py
Hello
Process finished with exit code 0
#coding: Utf-8
def f ():
return "Hello"/* Enter two return at a time, Only the first execution is the return execution after the function terminates */
return "RR"
z= f ()
Print z
D:\Python setup \python.exe c:/users /Huanhuan/pycharmprojects/untitled/ll.py
Hello
Process finished with exit code 0
Transfer tuples and dictionaries to functions
#coding: Utf-8
t= (' name ', ' Milo ')
def f (x, y):
print "% s:% s"% (x, y)/* Note this notation */
F (*t) /* Two values for output T-tuple */
D:\Python installer \python.exe c:/users//pycharmprojects/untitled/ll.py
name:milo
Process finished with exit code 0
#coding: Utf-8
def f (name= ' name ', age=0):
print "name:%s"% name
print "Age:%d"% age
F ("Milo", "9")
d={"name": ' Milo ', "Age": 20}/* Dictionary of Disorder */
F (**d)/* Defines method of dictionary invocation */
d={' a ':, ' n ': ' Milo '}
F (d [' N '],d[' a '])//* Two values to correspond */
D:\Python installer \python.exe c:/users//pycharmprojects/untitled/ll.py
Name:milo
age:30
Name:milo
age:20
Name:milo
age:9
Processing redundant real numbers
#coding: Utf-8
def f (x,*args):
print x
print args
F (
style= "color: #ff0000;" >def F (x,* Args,**kwargs):/* A * represents a tuple, two * * denotes dictionary */
print x
print args
print Kwargs
F (x=1,y=3,z=4)/*y=3,z=4 root tuple form */
D:\Python installer \python.exe c:/users/Huan/ pycharmprojects/untitled/ll.py
1
(2, 3)
1
()
{' Y ': 3, ' Z ': 4}
Process finished with exit code 0
Process finished with exit code 0
Python function notes