How to Convert Input to Integer in Python

To convert input to an integer in Python, you can use the int() function.

The following example shows how to convert input to an integer in Python using the int() function.

Using int() Function

We can use the int() function to convert input to an integer.

Suppose we have the following code:

# Take user input
age_str = input("Enter your age: ")

# Convert input into int
age_int = int(age_str)

# Show age_int
print(age_int)

Output: 👇️

Enter your age: 45
45

In this example, we use the int() function to convert the user input age_str to an integer age_int. The output shows the integer value converted from the input string using the int() function.

Conclusion

We can use the int() function to convert input to an integer in Python. This method provides a convenient way to handle numeric conversions from user input.