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.
is the equivalent*** of saying:
It is not the other way around, because the
int()function takes a string and converts it into anint. If you did it the other way around, the function wouldn't have anything to convert.*** : In Python functions are first-class objects. You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions. So there is no need to create
temp_varwithinput("something here)"and pass it as an argument tointusingint(temp_var)You can just use them directly like in :int(input("something here"))