如何在字符串中使用函数的结果?

时间:2014-12-08 21:13:11

标签: python

因此,当您定义一个函数并让该函数运行时,它将返回一个结果,但是如何在字符串中使用该结果?因为现在我得到了一些像

的代码
def chosen_snack():
    while True:
        print "What's your favourite type of snack?"
        fav_type = raw_input()
        if "sweet" in fav_type:
            print "So you like sweet snacks? I'll give you a lollipop!"
        elif "savoury" in fav_type:
            print "So you like savoury snacks? I'll give you some crisps!"
        else:
            print "sorry, what did you say? I only have savoury and sweet snacks."
            continue
        return

chosen_snack()

print "What will you do, eat it or save it?"
choice = raw_input("> ")

if "eat it" in choice:
    print "Well I  also would eat %s" % chosen_snack()

就像我想让所选的零食(所以一些薯片或棒棒糖)被%s“束缚”(我有意义吗?)但是如何

0 个答案:

没有答案