Python Forum
convert a string into an int in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: convert a string into an int in Python (/thread-15438.html)



convert a string into an int in Python - anjita - Jan-17-2019

How would I convert a string into an int in Python?


RE: convert a string into an int in Python - Larz60+ - Jan-17-2019

# this is string
mystring = '12345'

# convert to int
myint = int(mystring)



RE: convert a string into an int in Python - sandeepatel - Jan-18-2019

If a string contains only numerical characters, you can convert it into an integer using the int() function.

>>> int('227')
227

Let’s check the types:

>>> type('227')
<class ‘str’>

>>> type(int('227'))
<class ‘int’>