在python 3.3.4中的print语句中添加$infront of变量
我有以下声明:在python 3.3.4中的print语句中添加$infront of变量,python,Python,我有以下声明: print ("You have entered the price of ",var1, "for a chocolate bar") 它工作得很好,但是我需要在它前面加一个“$”作为输出。我试着把它隐藏在打印声明中,但是你最终会发现它之间有一个间隙,所以你最终会 'You have entered the price of $ 34.33 for a chocolate bar'. 我需要它是: 'You have entered the price of $34.33
print ("You have entered the price of ",var1, "for a chocolate bar")
它工作得很好,但是我需要在它前面加一个“$”作为输出。我试着把它隐藏在打印声明中,但是你最终会发现它之间有一个间隙,所以你最终会
'You have entered the price of $ 34.33 for a chocolate bar'.
我需要它是:
'You have entered the price of $34.33 for a chocolate bar'.
我对python非常陌生,这让我很困惑。
任何帮助都将不胜感激。建议使用python 3.3.4格式的Im来实现这一点
print("You have entered the price of ${0} for a chocolate bar".format(var1))
建议使用格式进行此操作
print("You have entered the price of ${0} for a chocolate bar".format(var1))
在哪里可以找到关于格式是推荐方式的文档?在哪里可以找到关于格式是推荐方式的文档?