Python-partition und split

Will ich split einen string mit zwei Wörtern wie "wort1 wort2" mit split-und partition und drucken (verwenden Sie eine für) die Wörter getrennt, wie:

Partition:
word1
word2

Split:
word1
word2

Dies ist mein code:

print("Hello World")
name = raw_input("Type your name: ")

train = 1,2
train1 = 1,2
print("Separation with partition: ")
for i in train1:
    print name.partition(" ")

print("Separation with split: ")
for i in train1:
    print name.split(" ")

Dies ist passiert:

Separation with partition: 
('word1', ' ', 'word2')
('word1', ' ', 'word2')

Separation with split: 
['word1', 'word2']
['word1', 'word2']
Schreibe einen Kommentar