DEV Community

Discussion on: Using Python Functions As Classes

Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky

Nice one :)

By the way you can turn classes into functions too:

class Foo:
    def __call__(self, a):
        print(f"Calling with a=", a)

foo = Foo()
foo(42)
Collapse
 
abdurrahmaanj profile image
Abdur-Rahmaan Janhangeer

Great! That's the needed comment to complement this article!

Collapse
 
vberlier profile image
Valentin Berlier

By the way you can do this:

In [1]: return_hello = lambda *args, **kwargs: 'hello'                   

In [2]: class Foo(metaclass=return_hello): ...                           

In [3]: Foo                                                              
Out[3]: 'hello'