text = "Please enter your weight in", Measurement_system
weight = input(text)
我希望为用户提供输入提示,而不用引号括起来
响应上面的代码,它显示:
('Please enter your weight in', 'imperial')
有谁知道如何摆脱这些引号? 谢谢:))
答案 0 :(得分:5)
您的text
值实际上是一个元组,因为您在分配text
时使用了逗号。相反,连接字符串。
text = "Please enter your weight in " + Measurement_system
weight = input(text)
或者你可以使用字符串格式化(虽然在这种情况下IMO有点矫枉过正):
text = "Please enter your weight in {}".format(Measurement_system)
weight = input(text)
或者,旧的字符串格式化语法
text = "Please enter your weight in %s" % Measurement_system
weight = input(text)