Python Forum
Question about types and py2 to py3 diffrences
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about types and py2 to py3 diffrences
#3
(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 generally is 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 the speed object could in theory override its == behavior to be equal, while no such flexibility exists for is. 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.speed
You 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 = speed
instead, I should say?
Reply


Messages In This Thread
RE: Question about types and py2 to py3 diffrences - by Vysero - Jun-22-2018, 05:42 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020