以下是我的代碼。我想用逗號分隔的列表追加ip:port字符串。在變量之間附加逗號
ip = ['1.1.1.1', '2.2.2.2', '3.3.3.3', '4.4.4.4']
memcache = ''
port = '11211'
for node in ip:
memcache += str(node) + ':' + port
# join this by comma but exclude last one
我想以這種格式輸出:
memcache = 1.1.1.1:11211, 2.2.2.2:11211, 3.3.3.3:11211, 4.4.4.4:11211
我怎樣才能做到這一點?
可能重複( http://stackoverflow.com/questions/16522362/concatenate-elements-of-a-list) –