def say_hello():
# 该块属于这一函数
print('hello world')
# 函数结束
say_hello() # 调用函数
say_hello() # 再次调用函数
def print_max(a,b):
if a > b:
print(a,'is maximum')
elif a==b:
print(a,'is equal to',b)
else:
print(b,'is maximum')
print_max(3,4)
x = 5
y = 7
print_max(x,y)
x = 50
def func(x):
global x #加了这一排,最后那行输出为2
print('x is', x)
x = 2
print('Changed local x to', x)
func(x)
print('x is still', x)
def say(message, times=1):
print(message * times)
say('Hello')
say('World', 5)
def func(a, b=5, c=10):
print('a is', a, 'and b is', b, 'and c is', c)
func(3, 7)
func(25, c=24)
func(c=50, a=100)
return 语句用于从函数中返回,也就是中断函数
def maximum(x,y):
if x > y:
return x
elif x ==y:
return 'the numbers are equal'
else:
return y
print(maximum(2,3))