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
[-] EveryMuffinIsNowEncrypted 1 points 5 months ago

I think I misworded my thoughts, to be honest.

As I understand it:

int(2.1) would print out 2 since it just converts it to an integer by truncating it.

float(2) would print out 2.0 since it just converts it to a floating-point value by appending a .0 to the end.

[-] eRac@lemmings.world 2 points 5 months ago

I feel the need to point out that a float isn't an integer with a decimal stuck on. A floating point number is called that because the precision on both sides of the decimal point changes depending on the size of the number.

It's actually stored as an exponent and a value to apply the exponent to. This allows you to express incredibly tiny numbers and incredibly large numbers, but the gaps between representable numbers is inconsistent.

You know how 10 / 3 * 3 is often not 10 because the decimal representation loses the repeating .33? In float, you run into the same issue but in much less predictable places.

[-] EveryMuffinIsNowEncrypted 1 points 5 months ago

Oh!

I think I've not quite gotten to that part yet in the lesson. Lol.

But it's good to know, so thanks for pointing that out! I'll be sure to remember it when I get to that point. Haha.

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

Python

6393 readers
12 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