def cheese_and_crackers(cheese_count, boxes_of_crackers): # 定义一个有两个参数的函数
print(f"You have {cheese_count} cheeses!")
print(f"You have {boxes_of_crackers} boxes of crackers!")
print("Man that's enough for a party!")
print("Get a blanket.\n")
print("We can just give the function numbers directly:")#直接给数字参数
cheese_and_crackers(20,30)
print("OR,we can use variables from our script:") # 通过变量给参数
amount_of_cheese = 10
amount_of_crackers = 50
cheese_and_crackers(amount_of_cheese,amount_of_crackers)
print("We can even do math inside too:") # 还可以用算式作为参数
cheese_and_crackers(10 + 20, 5 + 6)
print("And we can combine the two, variables and math:") #两个相结合既有变量又有运算
cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)
《Learn python3 the hard way》ex19 函数和变量
最新推荐文章于 2018-11-02 19:19:01 发布