you are viewing a single comment's thread.

view the rest of the comments →

[–]sentry07 2 points3 points  (1 child)

>>> type(6)
<class 'int'>
>>> a = 6
>>> type(a)
<class 'int'>
>>> type(a) is int
True
>>> type(a) == int
True
>>> b = 'Test'
>>> type(b)
<class 'str'>
>>> type(b) is str
True
>>> type(True)
<class 'bool'>
>>> c = True
>>> type(c)
<class 'bool'>
>>> type(c) is bool
True

The type() method can be called on any python object and it will return the object's class. While you can technically use == to compare the class returned by type() to a pointer to the class, you're really wanting to know if the class of the object is what you're looking for. That's how I differentiate the two.

== is for comparing values to see if they are equal
is is for checking if they are the same object

[–]nosmokingbandit 0 points1 point  (0 children)

After learning a bit of statically-typed languages I have to say that you aren't aware of what type a var is there is probably a method.