+ 1

What is the difference between int(input ()) and eval(input ()) ?

Python codes

6th Oct 2020, 8:44 AM
Noah Ayebu
Noah Ayebu - avatar
3 Answers
+ 6
eval will run any string as python code int just turns input type to integer
6th Oct 2020, 8:47 AM
Slick
Slick - avatar
+ 5
int(input("2+5")) will return Error, eval(input("2+5")) will return 7
6th Oct 2020, 10:12 AM
Shadoff
Shadoff - avatar
+ 4
With int(input()) this will be converted to integer data type so your input must be numbers not text/string by default input accept only string values and outputs a string data type.So use int to convert this string number to integer dtype.Instead eval will convert an operation done with numbers in string format to integer result so input will be integer.with int you can not perform operations like addition multiplication....
6th Oct 2020, 9:03 AM
HBhZ_C
HBhZ_C - avatar