我想打印如下内容:
你好7.16
这是我正在使用的代码
MyString = 'Hello'
MyFloat = 7.157777777
print "{} ¦ {0:.2f}".format(MyString, MyFloat)
但我得到了错误:
ValueError: cannot switch from automatic field numbering to manual field specification
如果我尝试:
MyString = 'Hello'
MyFloat = 7.157777777
print "{s} ¦ {0:.2f}".format(MyString, MyFloat)
或者str而不是s我得到错误:
KeyError: 's'
有什么办法可以打印一个带圆形浮点数的变量字符串吗?或者我应该使用类似%s
的东西吗?
目前没有回答
相关问题 更多 >
编程相关推荐