+ 1
Difference between x=input(int()) and x=int(input())
What is the difference between x=input(int()) and x=int(input()). Please Explain this.
6 Answers
+ 2
first one output 0 and wait/get for user input
second one wait/get user input (as string) and cast it to int... throwing error if not valid int ^^
+ 1
The future is now thanks to science int() doesn't convert only integer string to int...
int() is a class... calling it pass arguments provided to its __init__ method and return the related int if first arg can be converted to int ;)
+ 1
Great example visph .
Just tried it now. It also converts True to 1 and False to 0.
0
The future is now thanks to science you can pass float number to int (it return truncated value: 4.2 => 4, -4.2 => 4)... however, passing float number as string raise exception (not valid whole number) ^^
0
The future is now thanks to science int() initializer use __int__ magic method of any object... or __nonzero__ in case of no __int__ defined ;)
0
The future is now thanks to science my bad: int argument must be string, byte-like or number, not object ;P