Could someone help me understand the input() function? - eviltoast

I’m currently learning Python and am learning about very basic functions such as int(), float(), and input().

I have the first two down pat, but I’m struggling to understand the last. The example I’m looking at is found at 12:26 of this video:

nam = input('Who are you? ')
print('Welcome', nam)

Who are you? Chuck
Welcome Chuck

In this case, wouldn’t nam be a variable equal to the text on the right side of the = sign?

In which case, if nam is equal to input('Who are you? '), then wouldn’t print('Welcome', nam) just result in

Welcome input(Who are you? )?

Obviously not (nor does it work in a compiler), which leads me to believe I’m clearly misunderstanding something. But I’ve rewatched that section of the video several times, and looked it up elsewhere on the web, and I just can’t wrap my head around it.

Could someone help me with this?

Thanks.

  • Fahri Reza@mastodon.social
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    edit-2
    5 months ago

    @EveryMuffinIsNowEncrypted i maybe wrong

    input() is a python function that accepts arguments and returns value of type string.

    int() and float() are special type of functions called constructor, magical.

    int, or integer, on itself is a datatype like str, or string, is a datatype, to create an int you’d use its costructor int(‘23’) something like that

    int is a builtin datatype, so by typing 23, you already have an instance of int

    • WolfLink@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      5 months ago

      input prints the text based as an argument to the command line, waits for the user to type text followed by a new line to the command line, and returns the text as a string as its return value.

      TLDR input asks the user for text via the command line.