My teacher gave me this question: make a program that reads an integer and prints it. So I found this code:
integer_number = int(input("Enter an integer: "))
print("You entered:", integer_number)
I would like to understand why the function: "int" comes first than "input"
I expected the "input" function to be first than the "int" function since "input" has the function of requesting information from the user so that he can fill it in and the "int" converts a given string to an integer.
integer_number = int(input("something here"))
is just an abbreviated way of saying:
temp_var = input("something here")
integer_number = int(temp_var)
It is not the other way around, because the int()
function takes a string and converts it into an int
. If you did it the other way around, the function wouldn't have anything to convert.