0

Is there any convention or any functionality based selection of the formats in which we write classes, not classes actually but the empty bracket after the name, a bracket with object written in it and just a colon. When to use which? (python36)

Akshay
  • 11
  • 4
  • 1
    Are you in Python 3 or 2? – juanpa.arrivillaga Jun 23 '17 at 09:15
  • I am using python36 – Akshay Jun 23 '17 at 09:34
  • In Python 2, new-style classes had to be written as `class A(object)`, and old-style classes as `class A`. In python 3, there are only new-style classes, and the two alternatives are equivalent. People recommend you use `class A(object)` for compatibility reasons, but if that isn't a concern, you see just `class A` – juanpa.arrivillaga Jun 23 '17 at 09:36
  • Can you elaborate or give me source to get more info about what you mean by old style classes and new style classes, I didnt get it properly.. Do you mean the old and new python versions or else – Akshay Jun 23 '17 at 09:38
  • read the duplicate target.It has explanations and links to documentation. Or just google "old-style vs new-style classes". Honestly, old style classes only exist for the sake of backwards compatibility in old code written in Python 2. If you are on Python 3, there is no need to worry about this distinction. It doesn't exist in Python 3. – juanpa.arrivillaga Jun 23 '17 at 09:40
  • Ok, one last thing.. So now in python 3 what is the recommended way to write class, a semicolon or an empty bracket?.. () when args are required and : when not? – Akshay Jun 23 '17 at 09:43

0 Answers0