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.

  • Rimu@piefed.social
    link
    fedilink
    arrow-up
    1
    ·
    5 months ago

    Yes.

    The key concept here is the idea of a function.

    Remember in high school trigonometry there was sin, cos and tan? Those are functions. They take some number, do some math on it and give you back another number. “input()” is a function that takes a string as a parameter ('Who are you? ') and the work that function does is to wait for the user to type something. Whatever they type is returned by the function and stored in the “nam” variable.

    A variable is like a bucket for holding data. The label on the bucket (“nam”) is used to do things with the bucket and the data inside.