Convert Strings into Integers in Python

[Total: 1   Average: 5/5]

Just like the str() built-in, Python also offers a handy built-in which takes a String object as an argument and returns the corresponding integer object.

Example

# Here age is a string object
age = "21"
print(age)
# Converting string to integer
int_age = int(age)
print(int_age)

Output

21
21

 

admin
Leave a Reply

Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages