String Python连接字符串和变量

String Python连接字符串和变量,string,python-2.7,variables,string-concatenation,String,Python 2.7,Variables,String Concatenation,我正在尝试连接字符串和变量,我看到添加了新行 def convert_hostname(row_rack,ru_host,orig_hostname): if orig_hostname[0:9] == "ll21l01ms": print row_rack, print ru_host, temp_var = "ll21l01ls-" + row_rack + ru_host + ".com" print temp_var Output when

我正在尝试连接字符串和变量,我看到添加了新行

def convert_hostname(row_rack,ru_host,orig_hostname):
  if orig_hostname[0:9] == "ll21l01ms":
     print row_rack,
     print ru_host,
     temp_var = "ll21l01ls-" + row_rack + ru_host + ".com"
     print temp_var

Output when run :
0707
49
ll21l01ls-0707
49
.com
当我尝试打印temp_变量时,它会在连接过程中添加新行

具有输出的文件应如下所示:

0707
49
ll21l01ls-070749.com
有什么想法吗?

试试:

temp_var = "ll21l01ls-" + row_rack.strip() + ru_host.strip() + ".com"

它会添加新行,还是在不需要的地方添加空格?如果它正在添加您不需要的空间,那么.strip()将行_rack和ru_host连接起来,看看这是否有效,因为当您连接变量时,它没有理由添加空间,除非这些空间已经存在,谢谢!脱衣舞成功了!