On Tue, 15 May 2018 07:29:39 -0700, Mike McClain wrote:

> I had gotten the impression that everything in OOP is an object but
> you're all saying that variables are not objects.

Perhaps it is better to say every VALUE in Python is an object.

Keywords aren't values. Operators aren't values. Comments aren't values. 
Expressions like "5 + 3*x" themselves aren't values, but they evaluate to 
a value. Neither are variables/names.

Variables *hold* values, or if you prefer, names refer to values. But 
since they aren't themselves values, names/variables aren't objects.

> Does a variable have a type?

In Python, no, variables don't have types. Python uses *dynamic typing* 
which we can simplify a little and describe as:

- variables are just labels that can refer to any value;

- values are typed;

- the interpreter checks that types are compatible at runtime,
  when the code is executed

(e.g. "1 + 2" is permitted, but "1 + []" is not).


The most common alternative is *static typing*, where:

- variables are typed;

- variables are labels that can only refer to a value that matches
  that type;

- the compiler checks that types are compatible at compile-time,
  before the code is executed.



-- 
Steve

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to