在python中逐行连接两个字符串

时间:2017-03-02 13:18:04

标签: python string python-2.7

我有两个字符串如下:

comstr = ['year', 'doy', 'd_lon', 'd_lat']
datstr = ['2015', '112', '1.78218', '1.78218']

如何连接两个字符串?我想得到如下结果:

'year', 'doy', 'd_lon', 'd_lat'      # 1st row
'2015', '112', '1.78218', '1.78218'  # 2nd row

1 个答案:

答案 0 :(得分:0)

您可以使用:

com_list = ['year', 'doy', 'd_lon', 'd_lat']
dat_list = ['2015', '112', '1.78218', '1.78218']

for strings in [com_list, dat_list] :
    print(", ".join(["'%s'" % string for string in strings]))

输出:

'year', 'doy', 'd_lon', 'd_lat'
'2015', '112', '1.78218', '1.78218'