Sometimes, we want to split a string of space separated numbers into integers with Python.
In this article, we’ll look at how to split a string of space separated numbers into integers with Python.
How to split a string of space separated numbers into integers with Python?
To split a string of space separated numbers into integers with Python, we can use the split
method.
For instance, we write
l = "42 0".split()
to split the "42 0"
string by the spaces by calling split
with no argument.
A list is then returned with the split substrings inside.
Conclusion
To split a string of space separated numbers into integers with Python, we can use the split
method.