str.partition returns a tuple of three elements. The line before the section line, the section itself, and the rest of the line. Therefore, it should be used as
first, middle, rest = name.partition(" ") print first, rest
To use str.split you can just print split lines like this
print name.split(" ")
But, when you call it like this if the line contains more than one space, you will get more than two elements. for instance
name = "word1 word2 word3" print name.split(" ") # ['word1', 'word2', 'word3']
If you want to split only once, you can specify the number of times that you want to split, as a second parameter, for example
name = "word1 word2 word3" print name.split(" ", 1) # ['word1', 'word2 word3']
But, if you are trying to break based on the space characters, you do not need to pass " " . You can just do
name = "word1 word2 word3" print name.split() # ['word1', 'word2', 'word3']
If you want to limit the number of sections,
name = "word1 word2 word3" print name.split(None, 1) # ['word1', 'word2 word3']
Note: Using None in split or not specifying any parameters is what happens.
Quote from shared documentation
If sep is not specified or None, another separation algorithm is applied: consecutive space runs are treated as single delimiters, and the result will not contain empty lines at the beginning or end if the line has leading or trailing white space. As a result, splitting an empty string or a string consisting of just whitespace with a separator None returns [].
So you can change your program as follows
print "Partition:" first, middle, rest = name.partition(" ") for current_string in (first, rest): print current_string print "Split:" for current_string in name.split(" "): print current_string
Or you can use the str.join method similar to this
print "Partition:" first, middle, rest = name.partition(" ") print "\n".join((first, rest)) print "Split:" print "\n".join(name.split())