Sometimes, we want to convert number words to integers with Python.
In this article, we’ll look at how to convert number words to integers with Python.
How to convert number words to integers with Python?
To convert number words to integers with Python, we can use the word2number
module.
To install it, we run:
pip install word2number
Then we write:
from word2number import w2n
n = w2n.word_to_num("ten million three thousand nine hundred and twenty four")
print(n)
We call w2n.word_to_num
with the English number string that we want to convert into a number.
Then we assign the returned number to n
.
Therefore, n
is 10003924.
Conclusion
To convert number words to integers with Python, we can use the word2number
module.