def func(x):
print(
'方法体内x=', x)
x =
2
print(
"change local x to", x)
x =
50
func(x)
print(
'x=', x)
print(
'========================')
print(
'使用默认参数')
def say(message, time=1):
print(message * time)
say(
'hello')
say(
'hello',
5)
print(
'========================')
print(
'关键参数')
def func(a, b=5, c=10):
print(
'a=', a,
',b=', b,
',c=', c)
func(
0)
func(
0,
0)
func(
0,
0,
0)
func(
0, c=
1)
print(
'========================')
def maxNum(x, y):
if x > y:
return x
else:
return y
num1 = int(input(
'1输入数字:'))
num2 = int(input(
'2输入数字:'))
print(
'max result:')
print(maxNum(
20,
30))
print(
'========================')
print(
'文档字符串')
def printMaxValue(x, y):
'''print the max value of two '''
if x > y:
print(
'x ')
else:
print(
'y')
print(printMaxValue(
1,
2))
print(printMaxValue.__doc__)
运行结果 C:\Users\dell\AppData\Local\Programs\Python\Python35\python.exe O:/Python/demo7_3.py 方法体内x= 50 change local x to 2
x= 50
使用默认参数 hello
hellohellohellohellohello
关键参数 a= 0 ,b= 5 ,c= 10 a= 0 ,b= 0 ,c= 10 a= 0 ,b= 0 ,c= 0
a= 0 ,b= 5 ,c= 1
1输入数字:
转载请注明原文地址: https://ju.6miu.com/read-679575.html