how to use concatenate a fixed string and a variable in Python

人走茶凉 提交于 2019-11-28 08:58:10

I'm guessing that you meant to do this:

msg['Subject'] = "Auto Hella Restart Report " + sys.argv[1]
# To concatenate strings in python, use       ^ 

Try:

msg['Subject'] = "Auto Hella Restart Report " + sys.argv[1]

The + operator is overridden in python to concatenate strings.

Anto

If you need to add two strings you have to use the '+' operator

hence

msg['Subject'] = your string + sys.argv[1]

and also you have to import sys in the begining

as

import sys

msg['Subject'] = "Auto Hella Restart Report " + sys.argv[1]
Smith John
variable=" Hello..."  
print (variable)  
print("This is the Test File "+variable)  

for integer type ...

variable="  10"  
print (variable)  
print("This is the Test File "+str(variable))  

With python 3.6+:

msg['Subject'] = f"Auto Hella Restart Report {sys.argv[1]}"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!