How to convert a string to an integer in Python
To convert a string to an integer we can use the built-in int()
function in Python.
Here is an example that converts string 21
to an integer.
a = '21'
print(int(a)) # prints number 21
Output:
21
To convert a string to an integer we can use the built-in int()
function in Python.
Here is an example that converts string 21
to an integer.
a = '21'
print(int(a)) # prints number 21
Output:
21