定义函数格式:
def 函数名称(参数 = None):
代码组
其中 参数 = None ,设置默认值可为空
def printHello():
print('hello world')
def printHelloWithName(name):
print('hello world! ',name)
def printHell0WithTime(time=None):
print('hello world ! -',time)
def printStudent(name , age):
print('name: ', name , 'age: ', age)
def printMyFridend(name = '' , age = 0):
print("My friden is ",name,' age is ',age)
return "hah"
printHello()
printHelloWithName("Lily")
printHelloWithName("")
printHell0WithTime("今天")
printHell0WithTime()
printStudent('Lily',12)
printStudent('Lily','14 years old')
printMyFridend('Lucy',12)
printMyFridend('Lucy','13 years old')
网友评论