I looked in my book and in the documentation, and did this:
a = "hello"
b = a.split(sep= ' ')
print(b)
I get an error saying split() takes no keyword arguments. What is wrong?
I want to have [‘h’,’e’,’l’,’l’,’o’]
I tried not passing sep and just a.split(‘ ‘), and got [‘hello’]
Python allows a concept called “keyword arguments”, where you tell it which parameter you’re passing in the call to the function. However, the standard
split()function does not take this kind of parameter.To split a string into a list of characters, use
list():As an aside, an example of keyword parameters might be:
You can call this function in a few different ways:
Notice how you can change the order of keyword parameters.