I am new to python, and when I use the input() for any inputs including numbers it works, but my teacher is saying to use int(input()) for integer-based inputs. Can someone explain what is the difference between these syntaxes?
Asked
Active
Viewed 161 times
-1
-
Converts the input to integer. By default, inputs in Python are in string form. – Abhyuday Vaish May 09 '22 at 16:33
-
1Welcome to Stack Overflow. One of them has `int` around it, and the other doesn't. Consequently, where `int` is present, it does the thing that it normally does. To understand it properly, you should try reading documentation and/or following a tutorial. More to the point: if your teacher says something that you do not understand, you should **ask your teacher** for clarification. If someone tells you to do something and you do not understand why, the "why?" question is best directed at that person. – Karl Knechtel May 09 '22 at 16:35
-
It's good that you are asking this question but did you first ask your teacher about this? What did they say? – Abhyuday Vaish May 09 '22 at 16:36
-
I did ask them but they just repeated the statement, I didn't want to keep nagging them so I kept this question in the back of my mind. I am not saying they don't know the answer but I think they just didn't care? I guess?. – dash May 09 '22 at 16:42
-
@dash I understand. But you can always try to ask for some more clarification. – Abhyuday Vaish May 09 '22 at 16:44
1 Answers
2
input()
returns a string
.
To change it to a number(an integer
) do int()
, so it would be int(input())
.

kenntnisse
- 429
- 2
- 12