def tax(bill):
"""Adds 8% tax to a restaurant bill."""
bill *= 1.08
print "With tax: %f" % bill
return bill
def tip(bill):
"""Adds 15% tip to a restaurant bill."""
bill *= 1.15
print "With tip: %f" % bill
return bill
meal_cost = 100
meal_with_tax = tax(meal_cost)
meal_with_tip = tip(meal_with_tax)
正如你在账单旁边看到的那样,账单* = 1.08。我搜索谷歌,但刚刚得到“你的搜索 - * = - 与任何文件都不匹配。”
答案 0 :(得分:3)
这只是短暂的,
bill = bill * 1.08
示例:
>>> bill = 1.23
>>> bill *= 1.08
>>> bill
1.3284
>>> bill = 1.23
>>> bill = bill * 1.08
>>> bill
1.3284
>>>
答案 1 :(得分:2)
bill *= 1.15
与写作相同
bill = bill * 1.15
答案 2 :(得分:0)
它被称为赋值运算符。它将右操作数与左操作数相乘,并将结果赋给左操作数。