Could someone help me understand the input() function?
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.
Many people have given you answers of varying lengfhs, so I feel free to ask my counter-question...
You say you had int() and float() but would do you assume would happen if you had just replaced 'input(Who are you?)' with 'int(7)'? What value would be assigned to name if the statement was 'nam = int(7)'?
Following the logic you're espousing in the OP, 'nam' would be equal to the string "int(7)" and the print statement would output "Welcome int(7)". Either you understand why that wouldn't be the case and should see why your original example works. Or you don't and you should double check your understanding of functions and keep tapping people here for help.
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.