43

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.

you are viewing a single comment's thread
view the rest of the comments
[-] Uncaged_Jay@lemmy.world 4 points 5 months ago

I'm not sure if I'm the best at explaining this, as I'm more fluent in C++, but effectively what is happening is you're providing a prompt for the user's input. The user's input is then assigned to the variable.

In a lot of languages, this would be two lines of code and look something like this:

Output:"Please enter your name"

Name=input

Python is trying to simplify this process

[-] EveryMuffinIsNowEncrypted 1 points 5 months ago

So input(x) prints out x and then puts itself into a waiting mode of sorts, waiting for the user to supply a value, and then once it has that value it outputs that particular value.

Am I right?

this post was submitted on 12 Jun 2024
43 points (100.0% liked)

Python

6400 readers
8 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS