首先看代码函数定义,仔细看,仔细看结果,先上图,代码紧跟其后,相信肯定对你有用。
def hello():
"""
无参数函数定义:打印特定的字符串
"""
print('hello python ,hello world')
def hello1(name):
"""
形参
"""
print(f'hello {name} ,hello world')
def hello2(name,age):
"""
多参数
"""
print(f'hello {name} ,hello world,今年{age}岁')
def hello3(name,age=30):
"""
多参数,默认参数
"""
print(f'hello {name} ,hello world,今年{age}岁')
def hello4(name,age=30,*frinds):
"""
多参数,默认参数,不定长度参数
"""
print(f'hello {name} ,hello world,今年{age}岁,我有好朋友{frinds}')
help(hello)
help(hello1)
help(hello2)
help(hello3)
help(hello4)
hello()
hello1('李华')
hello2('李慢',30)
hello3('李快')
hello3('李华快',20)
hello4('李华慢',20,'王丽','王五','二麻子')
运行结果如下:
加油,一起学习python,分享使我快乐,加油⛽️