Python 3: str.join() with seperator

前端 未结 2 1783
滥情空心
滥情空心 2020-12-20 07:14

I have some code which is essentially this:

data = [\"some\", \"data\", \"lots\", \"of\", \"strings\"]
separator = \".\"

output_string = \"\"
for datum in d         


        
2条回答
  •  一生所求
    2020-12-20 07:25

    If the separator is a variable you can just use variable.join(iterable):

    data = ["some", "data", "lots", "of", "strings"]
    separator = "."
    
    
    print(separator.join(data))
    some.data.lots.of.strings
    

提交回复
热议问题