Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

OOP is not optional in Python though, unless you are speaking about pre-2.0 Python, before everything became object instances, Smalltalk style.
 help



You can have naked (top-level) functions in Python right? Are they also in instances of classes?

They definitely are,

       Python 3.15.0 (tags/v3.15.0:d220409, Oct  9 2026, 11:55:56) [MSC v.1951 64 bit (AMD64)] on win32
       Enter "help" below or click "Help" above for more information.
       >>> def sum(x,y):
              return x + y

       >>> sum(40, 2)
       42

       >>> type(sum)
       <class 'function'>

       >>> dir(sum)
       ['__annotate__', '__annotations__', '__builtins__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__getstate__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__type_params__']

Functions are an object in Python too, I think that's why they're trying to get at. So you can do some funky things with them if you really want.

You certainly don't have to write OO Python if you don't want to. Objecting to functions being objects like the person you're replying to is, is a flavour of puritanism I find baffling.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: