What is a "Pythonic" way to define a class that does not need any constructor parameters?
class MyClass:
# class body
or do we need an explicit constructor? i.e.
class MyClass:
def __init__:
pass
# class body
What is a "Pythonic" way to define a class that does not need any constructor parameters?
class MyClass:
# class body
or do we need an explicit constructor? i.e.
class MyClass:
def __init__:
pass
# class body
Your first approach is good enough, unless you want to only use class attributes and not instance attributes
Also every class in Python inherits from object, as explained in detail here
class MyClass:
pass
An example of such classes might be as follows
class MyClass:
a = 1
b = 2
print(MyClass.a)
#1
print(MyClass.b)
#2
class MyException(Exception):
pass
raise MyException
# raise MyException
#__main__.MyException