1

With or without parenthesis, is there a difference?

class Host:
def __init__(self, ip, elements):

class Interface():
def __init__(self, localIP, remoteIP, numHops, hops):
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
qz_99
  • 185
  • 1
  • 12
  • Does this answer your question? [Python class definition syntax](https://stackoverflow.com/questions/4109552/python-class-definition-syntax) – Prashant Kumar Jan 14 '20 at 11:38

2 Answers2

3

No, there is no difference whatsoever, and any half-decent IDE will suggest you to "remove redundant parenthesis".

In Python 2 days there was a difference between class Host and class Host(object) (see What is the difference between old style and new style classes in Python?).

In Python 3, class Host, class Host(object) and class Host() are all equivalent.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
0

Typically, parentheses in class definitions are used to indicate inheritance:

class Interface(baseClass):

If your class does not inherit any properties from another object, then it is more natural to omit parentheses:

class Interface:
Giorgos Myrianthous
  • 36,235
  • 20
  • 134
  • 156