variable vs. object
André Roberge
andre.roberge at gmail.com
Sun Nov 29 21:24:21 EST 2015
On Sunday, 29 November 2015 22:06:58 UTC-4, fl wrote:
> Hi,
>
> I read several parts on line about Python that everything in Python is an
> object. Yes, it is a key difference with other languages. Then, I read a page
> it says variables: global and local variable at:
>
> http://www.tutorialspoint.com/python/python_functions.htm
>
>
> I have a question that whether variables are objects?
>
> For example,
>
> a=10
>
> 'a' is an integer. Is it an object too?
>
> Thanks,
In Python, a "variable" is a name given to an object. In Python, the "=" sign is used to assign a name to an object: the name is on the left-hand side, and the object is on the right hand side. Multiple names can be assigned to the same object. In the example you gave, "a" is a name given to the object "10" which is an integer.
If you do:
a = 10
b = a
a = "hello"
b will be 10. b was just another name given to object 10 to which the name "a" was referring to at that point, even though we decided later that a should refer to the string "hello" (which is an object).
André
More information about the Python-list
mailing list