Question:
Basic Python question?
?
2011-04-05 16:53:33 UTC
I'm using IDLE to learn Python and I'm wondering if

>>> x = 5
>>> x
5
>>> x = Hello
>>> x
Hello


If I were writing a Python program in Notepad, and I used that code in that order, does x=Hello only after I declare it, and does x = 5 only after I declare it and before I declare x = Hello

???

Thank you.
Five answers:
Silent
2011-04-05 16:55:32 UTC
Yes.



That assumes that in your program you put quotes around your string Hello, so that it'll actually work. Right now you're setting x equal to the value of a variable called Hello, which you haven't defined.
thvtm
2011-04-05 16:57:17 UTC
Yes, you are correct. That is the difference between a PROCEDURAL language like Python (where each command is processed one after another) differs from a DECLARATIVE language like Html.



For each line, the program has a state. At the start, the state consists of x being undefined.

After 'x = 5', x is now 5 -- the line SETS x to be equal to 5. After 'x = Hello', x is changed to be hello.
?
2016-11-06 13:33:51 UTC
because of the fact celsius you entered is a string, 3 * "a"="aaa", 3* "3"="333", convert celsius into an int via doing int(celsius), verify you assign the conversion to a variable via doing b=int(celsius) and multiply variable b via farenheit. or you're able to do: celsius=int(enter("temp in celsius")) in the 2d way you will use celsius because of the fact the variable. via the way python 3 is the main cutting-edge version, study 3 or atleast between the later variations of python 2
William
2011-04-05 16:56:23 UTC
i too am sort of a noob at python but i know the answer to your question is yes
Tasm
2011-04-05 16:58:25 UTC
yep x equal what ever you set it to when you set it. So when you set it again, you overwrite the first value.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...