Since Python 3, input returns a string which you have to explicitly convert to int, like this

x = int(input("Enter a number: "))
y = int(input("Enter a number: "))

You can accept numbers of any base like this

>>> data = int(input("Enter a number: "), 8)
Enter a number: 777
>>> data
511
>>> data = int(input("Enter a number: "), 16)
Enter a number: FFFF
>>> data
65535
>>> data = int(input("Enter a number: "), 2)
Enter a number: 10101010101
>>> data
1365

The second parameter tells it the base of the number and then internally it understands and converts it. If the entered data is wrong it will throw a ValueError.

>>> data = int(input("Enter a number: "), 2)
Enter a number: 1234
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: invalid literal for int() with base 2: '1234'

For values that can have a fractional component, the type would be float rather than int:

x = float(input("Enter a number:"))

Differences between Python 2 and 3

Summary

  • Python 2's input function evaluated the received data, converting it to an integer implicitly (read the next section to understand the implication), but Python 3's input function does not do that anymore.
  • Python 2's equivalent of Python 3's input is the raw_input function.

Python 2.x

There were two functions to get user input, called input and raw_input. The difference between them is, raw_input doesn't evaluate the data and returns as it is, in string form. But, input will evaluate whatever you entered and the result of evaluation will be returned. For example,

>>> import sys
>>> sys.version
'2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]'
>>> data = input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
(22, <type 'int'>)

The data 5 + 17 is evaluated and the result is 22. When it evaluates the expression 5 + 17, it detects that you are adding two numbers and so the result will also be of the same int type. So, the type conversion is done for free, and 22 is returned as the result of the input and stored in the data variable. You can think of input as the raw_input composed with an eval call.

>>> data = eval(raw_input("Enter a number: "))
Enter a number: 5 + 17
>>> data, type(data)
(22, <type 'int'>)

Note: You should be careful when you are using input in Python 2.x. I explained why one should be careful when using it, in this answer.

But, raw_input doesn't evaluate the input and returns as it is, as a string.

>>> import sys
>>> sys.version
'2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]'
>>> data = raw_input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
('5 + 17', <type 'str'>)

Python 3.x

Python 3.x's input and Python 2.x's raw_input are similar and raw_input is not available in Python 3.x.

>>> import sys
>>> sys.version
'3.4.0 (default, Apr 11 2014, 13:05:11) \n[GCC 4.8.2]'
>>> data = input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
('5 + 17', <class 'str'>)
Answer from thefourtheye on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-take-integer-input-in-python
How to take integer input in Python? - GeeksforGeeks
April 3, 2026 - Interview Questions ยท Examples ... input() function always returns a string. To take integer input, the string must be typecast into an integer using the int() function....
๐ŸŒ
Real Python
realpython.com โ€บ python-input-integer
How to Read Python Input as Integers โ€“ Real Python
March 18, 2026 - Youโ€™re going to leverage Pythonโ€™s own error-handling mechanism. By default, the integer conversion will throw a ValueError exception if it fails. Try the above code again, but this time, notice how it behaves with bad input: ... >>> number_as_string = input("Please enter an integer: ") Please enter an integer: rutabaga >>> number_as_integer = int(number_as_string) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: 'rutabaga'
๐ŸŒ
Hyperskill
hyperskill.org โ€บ university โ€บ python โ€บ input-and-input-in-python
Python input() Function: Get User Input with Examples
June 5, 2026 - When you use the input() function ... typing '123' is seen as the string '123'. On the hand for integer input you need to change the string input into an integer using the int() function....
Top answer
1 of 10
407

Since Python 3, input returns a string which you have to explicitly convert to int, like this

x = int(input("Enter a number: "))
y = int(input("Enter a number: "))

You can accept numbers of any base like this

>>> data = int(input("Enter a number: "), 8)
Enter a number: 777
>>> data
511
>>> data = int(input("Enter a number: "), 16)
Enter a number: FFFF
>>> data
65535
>>> data = int(input("Enter a number: "), 2)
Enter a number: 10101010101
>>> data
1365

The second parameter tells it the base of the number and then internally it understands and converts it. If the entered data is wrong it will throw a ValueError.

>>> data = int(input("Enter a number: "), 2)
Enter a number: 1234
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: invalid literal for int() with base 2: '1234'

For values that can have a fractional component, the type would be float rather than int:

x = float(input("Enter a number:"))

Differences between Python 2 and 3

Summary

  • Python 2's input function evaluated the received data, converting it to an integer implicitly (read the next section to understand the implication), but Python 3's input function does not do that anymore.
  • Python 2's equivalent of Python 3's input is the raw_input function.

Python 2.x

There were two functions to get user input, called input and raw_input. The difference between them is, raw_input doesn't evaluate the data and returns as it is, in string form. But, input will evaluate whatever you entered and the result of evaluation will be returned. For example,

>>> import sys
>>> sys.version
'2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]'
>>> data = input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
(22, <type 'int'>)

The data 5 + 17 is evaluated and the result is 22. When it evaluates the expression 5 + 17, it detects that you are adding two numbers and so the result will also be of the same int type. So, the type conversion is done for free, and 22 is returned as the result of the input and stored in the data variable. You can think of input as the raw_input composed with an eval call.

>>> data = eval(raw_input("Enter a number: "))
Enter a number: 5 + 17
>>> data, type(data)
(22, <type 'int'>)

Note: You should be careful when you are using input in Python 2.x. I explained why one should be careful when using it, in this answer.

But, raw_input doesn't evaluate the input and returns as it is, as a string.

>>> import sys
>>> sys.version
'2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]'
>>> data = raw_input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
('5 + 17', <type 'str'>)

Python 3.x

Python 3.x's input and Python 2.x's raw_input are similar and raw_input is not available in Python 3.x.

>>> import sys
>>> sys.version
'3.4.0 (default, Apr 11 2014, 13:05:11) \n[GCC 4.8.2]'
>>> data = input("Enter a number: ")
Enter a number: 5 + 17
>>> data, type(data)
('5 + 17', <class 'str'>)
2 of 10
54

In Python 3.x, raw_input was renamed to input and the Python 2.x input was removed.

This means that, just like raw_input, input in Python 3.x always returns a string object.

To fix the problem, you need to explicitly make those inputs into integers by putting them in int:

x = int(input("Enter a number: "))
y = int(input("Enter a number: "))
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ python-basic-exercise-10.php
Python: Input an integer (n) and computes the value of n+nn+nnn - w3resource
May 17, 2025 - A base-n literal consists of the digits 0 to n-1, with a to z (or A to Z) having values 10 to 35. The default base is 10. The allowed values are 0 and 2-36. Base-2, -8, and -16 literals can be optionally prefixed with 0b/0B, 0o/0O, or 0x/0X, ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_int.asp
Python int() Function
The int() function converts the specified value into an integer number. ... Coding fundamentals as bite-sized lessons and challenges. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to take int input in Python โ€” safely and correctly - YouTube
Trying to get numeric input from your user? If you're running int on the result of the input function, then you're likely going to have problems. How can we ...
Published: July 13, 2025
Find elsewhere
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
I'm new to python: convention question - Python Help - Discussions on Python.org
July 14, 2023 - Iโ€™m new to python. I wanted to know if when I use the input command, is it common to write the type of variable we expect to recieve from the input? For example: num = int(input()) The other option: just num=input() โ€ฆ
Top answer
1 of 5
7
integer_number = int(input("something here"))

is just an abbreviated way of saying:

temp_var = input("something here")
integer_number = int(temp_var)

It is not the other way around, because the int() function takes a string and converts it into an int. If you did it the other way around, the function wouldn't have anything to convert.

2 of 5
2

In Python you can pass functions as arguments of another function and of course they'll be evaluated before the outer function. Guess I should point you to the relevant official Python documentation that states that, but just googling for it isn't working right now.

See Pythonโ€™s Functions Are First-Class:

Python's functions are first-class objects. You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions.

Got a nice answer about that on SO :

What are "first-class" objects:

In short, it means there are no restrictions on the object's use. It's the same as any other object.

A first class object is an entity that can be dynamically created, destroyed, passed to a function, returned as a value, and have all the rights as other variables in the programming language have.

Your one is not the first question about that:

All arguments are evaluated before the function is called:

Answer:

You are right, all arguments are evaluated before the function is called, otherwise the function cannot know what is passed to it. So what you are doing is actually:

but no link to docs here too.

Took a while, I found it here:

6.3.4. Calls its the link for Python 3:

...............All argument expressions are evaluated before the call is attempted. Please refer to section Function definitions for the syntax of formal parameter lists.........

๐ŸŒ
Pierian Training
pieriantraining.com โ€บ home โ€บ python tutorial: how to take an integer input in python
Python Tutorial: How to take an integer input in Python - Pierian Training
April 12, 2023 - Therefore, you would need to explicitly convert the input to an integer using `int()`. In conclusion, taking integer input in Python is a simple task that can be accomplished using the `input()` function. However, it is important to note that the `input()` function returns a string value even if the user inputs an integer.
๐ŸŒ
ScriptVerse
scriptverse.dev โ€บ tutorials โ€บ python-program-integer-input.html
Read/Take Number/Integer Input in Python 3 - ScriptVerse
Python has the built-in function called input() which prints the passed argument as a prompt into the screen, without a trailing newline.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-difference-between-int-input-and-input-int-in-Python
What is the difference between 'int (input()) and input (int())' in Python? - Quora
Answer (1 of 4): Dear Shiva, Lets write some code to understand it thoroughly. [code]# question - take a number as input and print it's thrice #it is simple right num = int(input("enter num")) #here when the input function takes an input it is in a string format hence we need conversion because...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_user_input.asp
Python User Input
The following example asks for your name, and when you enter a name, it gets printed on the screen: ... Python stops executing when it comes to the input() function, and continues when the user has given some input. In the example above, the user had to input their name on a new line.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to Take Integer Input in Python | input() Function Explained | ICS & Beginners Lecture - YouTube
Source Code for this lecture:๐Ÿ”— https://github.com/engrayaz/python-for-math-and-ics-studentsIn this short lecture, we learn how to take integer input from th
Published: April 9, 2026
๐ŸŒ
101 Computing
101computing.net โ€บ home โ€บ python challenges โ€บ python tip: validating user input as number (integer)
Python Tip: Validating user input as number (Integer) - 101 Computing
July 14, 2025 - To use them as integers you will need to convert the user input into an integer using the int() function. e.g. ... This line of code would work fine as long as the user enters an integer.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python Tutorial: Integer Input - YouTube
Unlock the power of handling integer input in Python with our comprehensive tutorial! In this video, we delve into how to efficiently read and process intege...
Published: June 25, 2024
๐ŸŒ
Kansas State University
textbooks.cs.ksu.edu โ€บ intro-python โ€บ 03-strings-input โ€บ 02-number-input
Numerical Input :: Introduction to Python
July 30, 2026 - Of course, we can also read numerical input in Python using the input() function. To do this, we must simply use either the int() or float() function to convert the input received as a string to the correct data type.