+ 1
Is whatever given as input in python is taken as string
s=input() Input given is 3 Is s string or int
3 odpowiedzi
+ 1
Yes if no type is specified in input() python treat it as string.
You can see that in the example here👇, when I operate on "s", it is treated as string not an integer even if the input is integer or float
https://code.sololearn.com/cj2SO26rBfc8/?ref=app
0
Its a string and so it has to be. How would you know what the programmer is asking for? Maybe a user name, for which I choose "123".
If you need an int, use "x=int(input())".
0
Computers only understand binary (0/1 => on/off => 0/5v)... until they are programmed to handle other kind of values.
With these binary values, CPU are made to handle multiple of groups of 8 bits (bytes, historically the max, then comes 16 bits CPU, 32 bits, 64 bits...), so the computer more generally "understand" integers from 0 to 2 power n (excluded, where n is the number of bits).
Quite same for signed integers, and floating point (real) numbers... but that's not really a concern for now ^^
Input are done by translating char entered by user through a char encoding convention (ascii, unicode, ...) where a char is nothing else than an integer for the computer...
That's the reason of the "string" return type of input() function: charge to the programmer to do type conversion (cast) according to the context needs (you could even define specialized helpers function wich encapsulate the input call and the type cast ;))