String module, so it requires two parameters, one is a list, and the other is a separator. And when called, as Cnxo shows, if you import a string module:
Import string
You need to use String.Join () for this.
But now the string object itself has such a method that it requires only one delimiter parameter. Usage is:
' + '. Join (List1)
The simplest we use is the Join function, the instance
print '. Join (List (' Hello '))
Connect the data
Word1 = "A"
Word2 = "few"
Word3 = "good"
Word4 = "Words"
Wordlist = ["A", "few", "more", "good", "words"]
Print "Words:" + word1 + word2 + word3 + word4
Print "List: +". Join (Wordlist)
Instance
Word1 = "A"
Word2 = "few"
Word3 = "good"
Word4 = "Words"
Wordlist = ["A", "few", "more", "good", "words"]
#Joining a list of words
Sentence = "Second:"
For word in wordlist:
Sentence + = "" + Word
Sentence = "."
Print sentence
Take a look at the example above
# Splitting strings
string1 = "A, B, C, D, E, F"
Print "String is:", string1
Print "Split string by Spaces:", String1.split ()
Print "Split string by commas:", String1.split (",")
Print "Split string by commas, max 2:", String1.split (",", 2)
Print
# Joining Strings
List1 = ["A", "B", "C", "D", "E", "F"]
string2 = "___"
Print "List is:", List1
print ' Joining with '%s ':%s '
% (string2, String2.join (List1))
print ' Joining with '-.-': ', '-.-'. Join (List1)