Message from Python discussions

December 2018

— a is not a float, it remains being a string, because you read it from input


You can't cast from string to integer if the string is not correctly formatted (and you can't assure it will), but you can cast from float to integer because Python knows how to handle numbers

— A str cant be converted to int by int ()? oh thanks i dont know this. thanks a lot, cj.

— It can, if it is correctly formatted

— Look at it rookie

— In both cases a is a str

— In the first one, a is '5', it can be converted to int
in the second one, a is '5.5', it can't be converted to int, you have to cast it to float first

Message permanent page

— Rookie
You can think of it like this
when a = 5.5
You cannot simply say
B = int(a)
Because that would be like saying
B = int(5.5)
And int cannot take a float value thus this will throw you an error

Message permanent page

— Look at it rookie you can cast to float in both cases

— Have you noticed the difference?

— So 5.5 a not incorrect form? a float 5.5 can and a str 5.5 cant. is there any chance the python can tell the dot "."from str? maybe python sentenced the dot to be and only can be a full stop?

Message permanent page

— a is a str... you can't cast a str without knowing what it contains, see this: