def print_hello(): #定义函数名,不要与系统自带函数名冲突,以免出错
print("hello1")
print("hello2")
print("hello3")
print_hello() #只有调用函数,才会执行函数里面的内容
#运行结果:
hello1
hello2
hello3
#函数里面嵌套函数
def hello():
print("hello")
def world():
print("world")
world()
hello()
#定义函数的时候的变量 叫形参(可以任意起名)
def welcome(a):
print('hello',a)
#真实的数据信息,调用函数的时候传的参数叫实参
welcome('lily')
welcome('laoli')
"""
参数:形参 实参
形参: 位置参数 默认参数 可变参数 关键字参数
"""
#位置参数:形参和实参个数必须保持一致,最好按位置传参
def getInfo(name,age):
print(name,age)
getInfo('westos',11)
getInfo(age=11,name='westos')
#默认参数:形参和实参可以不一