Python 连接一个字符串和一个变量
Python concatenate a string and a variable
我正在尝试连接字符串和变量,我看到添加了新行..
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_var 时,它会在连接期间添加新行。
with 输出应该是这样的:
0707
49
ll21l01ls-070749.com
有什么想法吗?
尝试:
temp_var = "ll21l01ls-" + row_rack.strip() + ru_host.strip() + ".com"
我正在尝试连接字符串和变量,我看到添加了新行..
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_var 时,它会在连接期间添加新行。
with 输出应该是这样的:
0707
49
ll21l01ls-070749.com
有什么想法吗?
尝试:
temp_var = "ll21l01ls-" + row_rack.strip() + ru_host.strip() + ".com"