Categories
Python Answers

How to split a string of space separated numbers into integers with Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *