• 4 Posts
  • 521 Comments
Joined 1 year ago
cake
Cake day: July 4th, 2023

help-circle




  • So what it comes down to is that int(), float(), and input() (as well as print()) are functions that you are calling. In the case of int() and float(), they return (simply put, when you make a function call it “becomes” the return value) an int or float type object based on the argument (the value between the parentheses) that you passed in. In the case of print(), it causes the program to print out the provided argument.

    input() is a little more complicated. It prints out the provided argument (in your case: Who are you? ) and then puts the program on pause while it waits for the user to input some text and press enter. Once they have done so, the input function returns the text the user has entered. So as mentioned before, the code input('Who are you? ') “becomes” the text the user input, which then gets assigned to the variable nam.

    I think where you may be getting confused is what exactly defines “text”. The only things that python considers text (referred to as a string) are characters surrounded by “” or ‘’. In your example, input('Who are you? ') is not a string, but code to be executed (although the argument being passed to input, 'Who are you? ', is a string). As an experiment, try surrounding that code with quotation marks (name = "input('Who are you? ')") and see what happens!