#创建函数cheese_and_crackers,其中参数为cheese_count和boxes_of_crackers.defcheese_and_crackers(cheese_count,boxes_of_crackers):print(f"You have {cheese_count} cheeses!")#打印,字符串化cheese_count参数print(f"You have {boxes_of_crackers} boxes 0f crackers!")#打印, 字符串格式化参数boxes_of_crackersprint("Man that's enough for a party!")#打印print("Get a blanket.\n")#打印,\n转义字符,换行print("We are 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)
输出结果
We are just give the function numbers directly:
You have 20 cheeses!
You have 30 boxes 0f crackers!
Man that's enough for a party!
Get a blanket.
OR,we can use variables from our script:
You have 10 cheeses!
You have 50 boxes 0f crackers!
Man that's enough for a party!
Get a blanket.
We can even do math inside too:
You have 30 cheeses!
You have 11 boxes 0f crackers!
Man that's enough for a party!
Get a blanket.
And we can combine the two, variables and math:
You have 110 cheeses!
You have 1050 boxes 0f crackers!
Man that's enough for a party!
Get a blanket.