Jun-22-2018, 05:42 PM
(Jun-22-2018, 05:32 PM)micseydel Wrote:(Jun-22-2018, 04:39 PM)Vysero Wrote: I guess what confuses me (coming from the java world) when I think of objects I think of having access to said objects methods. However, there are no methods for NoneType so what was the point on making it a class?Python doesn't have null like Java does. So None is like Java's null, except that it's an object, since Python doesn't have Java's notion of primitives.
For the other part of your question - yes, you can use == with None but generallyis
is preferred since None is a singleton object and what you really want is identity, not equality (by default nothing in Python is equal to None, but thespeed
object could in theory override its == behavior to be equal, while no such flexibility exists foris
. Generally, type-checking is discouraged in Python.
Ah I see so I should be saying (in both py2 and py3):
if speed is None: speed = self.data.speedYou said type checking is discouraged in Python, can you clarify? For instance, with my example how else might I go about setting speed = self.data.speed when speed = None but not when it already has a value? For instance:
if speed is None: speed = self.data.speed self.data.speed = speedinstead, I should say?