8-1
def display_message():
print("we will learn function in this chapter. ")
display_message()8-2
def favorite_book(title):
print("One of my favorite books is " + title +". ")
favorite_book("Alice in Wonderland")8-3
def make_shirt(size, words):
print("Size: " + size +"\tWords: " + words)
make_shirt("XL", "PICK & ROLL")
make_shirt(size = "XL", words = "PICK & ROLL")8-4
def make_shirt(size = "L", words = "I love python"):
print("Size: " + size +"\tWords: " + words)
make_shirt()
make_shirt("M")
make_shirt(words = "PICK & ROLL")8-5
def describe_city(city = "Tokyo", country = "The Holy Empire of Britannia"):
print(city + " is in " + country +". ")
describe_city()
describe_city("Pendragon")
describe_city("Luoyang", "Chinese Federation")8-6
def city_country(city, country):
print(city + ", " + country)
city_country("London", "EU")
city_country("Pendragon", "The Holy Empire of Britannia")
city_country("Luoyang", "Chinese Federation")8-7
def make_album(singer_name, album_name):
return {'singer': singer_name, 'album': album_name}
print(make_album("Jay Chou", "Fantasy"))
print(make_album("Eason", "Live For Today"))
print(make_album("Eason", "Shall We Dance? Shall We Talk!"))def make_album(singer_name, album_name, num=''):
return {'singer': singer_name, 'album': album_name, 'numbers': num}
print(make_album("Jay Chou", "Fantasy"))
print(make_album("Eason", "Live For Today"))
print(make_album("Eason", "Shall We Dance? Shall We Talk!", 10))
本文通过几个示例介绍了Python中函数的基本定义与调用方法,包括默认参数、关键字参数及返回值等特性。
2733

被折叠的 条评论
为什么被折叠?



