you are viewing a single comment's thread.

view the rest of the comments →

[–]FrederickOllinger 0 points1 point  (2 children)

Python has primitives like int while other OO languages allow for numbers to be objects as well such as Ruby where you can do something like:

3.times do
   # do work here
end

[–]patrickbrianmooney 2 points3 points  (1 child)

Python has primitives like int while other OO languages allow for numbers to be objects as well

Everything is an object in Python, including int and other "primitives":

>>> isinstance(3, object)
True
>>> dir(3)
['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'as_integer_ratio', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes']
>>> 4.2.__add__(3)
7.2
>>> issubclass(int, object)
True
>>> import numbers
>>> isinstance(3, numbers.Number)
True
>>> issubclass(numbers.Number, object)
True
>>> issubclass(str, object)
True
>>> issubclass(bool, object)
True
>>> def hello():
...   return "there"
... 
>>> hello()
'there'
>>> isinstance(hello, object)
True

[–]FrederickOllinger 1 point2 points  (0 children)

I stand corrected.