简体   繁体   English

如何从字符串中删除这些撇号

[英]How do I remove these apostrophes from the string

print("ENEMY Health is ", (int(ehealth), ' / ', (int(emaxHealth))), sep='')

Should look like: ENEMY Health is 100 / 100 应该看起来像: ENEMY Health is 100 / 100

but it looks like this: ENEMY Health is (100, ' / ', 100) 但它看起来像这样: ENEMY Health is (100, ' / ', 100)

Whats the go with this? 这是怎么回事?

By enclosing the health ratio in brackets, you are creating on the fly a Python tuple . 通过将运行状况比率括在方括号中,可以即时创建一个Python 元组 Calling print on that tuple will result in printing its string representation. 在该元组上调用print将导致打印其字符串表示形式。 So you have three elements enclosed in brackets and separated by commas, two of them being numbers (no quotes), and the one in the middle being a string (hence the quotes). 因此,您将三个元素括在方括号中并用逗号分隔,其中两个是数字(不带引号),中间的一个是字符串(因此带引号)。

Your line of code could be: 您的代码行可能是:

print("ENEMY Health is {0} / {1}".format(ehealth, emaxHealth))

Remove the brackets present inside the print function. 卸下打印功能内部的支架。

>>> ehealth = 100
>>> emaxHealth = 100
>>> print("ENEMY Health is ",str(ehealth),' / ',str(emaxHealth), sep='')
ENEMY Health is 100 / 100

OR 要么

>>> print("ENEMY Health is "+str(ehealth)+' / '+str(emaxHealth))
ENEMY Health is 100 / 100

OR 要么

>>> print("ENEMY Health is {} / {}".format(ehealth, emaxHealth))
ENEMY Health is 100 / 100

Im more familiar with java is but II think maybe change to quote's! 我对Java更熟悉,但II认为可能会更改为引号! print("ENEMY Health is ",(int(ehealth), "/" ,(int(emaxhealth)))) or take out quotes and apostrophies and leave the / where it is. print(“ ENEMY Health is”,(int(ehealth),“ /”,(int(emaxhealth)))))或取出引号和撇号,然后将/保留在原处。 hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM