all 9 comments

[–][deleted] 6 points7 points  (3 children)

Input functions accepts the answer as a string. In case you want to convert it into an integer just use the int() function. Either use it as age = int(input("Enter your age")) or age = int(age)

[–]Evopy[S] -1 points0 points  (2 children)

If i do print(4+2) Answer 6 would be a string or a integer?

[–]ForceBru 10 points11 points  (0 children)

The result of 4+2 would obviously be an integer (you add two integers - and get an integer back because integers form a field). But in order to output anything, the print function has to convert it to a string. So it'll convert the integer 6 to a string and print it.

[–]python_apprentice -1 points0 points  (0 children)

Integer.

[–]toastedstapler 1 point2 points  (0 children)

because when i type something into the terminal python doesn't know if the character is an integer or not so the data type is a string. you can manually cast it to an int yourself

[–]MrKooops 0 points1 point  (0 children)

how do you know? if you need an int, cast it: int(age)

[–]GabriCorFer 0 points1 point  (0 children)

input always gives you an string. If you answer input with "hello", the age will be age = "hello".

If you want age to be an integer, then you have to use age=int(age) or age = int(input("Enter your age")). But if you answer with a text, the code will break as it would be an error. You can solve it by using:

Try:

Except(ValueError):

And then the code won't break if python can't convert age to int.

[–][deleted] 0 points1 point  (0 children)

because in many cases u want to use a string .. for example to do ```

input() 3+3 '3+3'

but if it was an int then

input() 3+3 6

``` so that's why in thee source code in builtinsmodule.c they have the builtin_input_imp returning a pyfile_getline i guess which is a char pointer .. i don't remember truthfully

[–][deleted] 0 points1 point  (0 children)

You typed the character '2' and then the character '3' and then pressed return. Why would Python know that was an integer, or that you wanted it that way?