Bottom Page

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Defining parent Class in Python 2.7.11
#1
Hi everybody,
I am new to programming, I have networking back ground.
These days I am learning OOP.
I noticed following:
I can define parent class with out ()as shown in example#1, I can also define parent class with ()as shown in example#2. what is the conventional way to define Parent class is it with () or without ()?

Thanks and have a good weekend!!

# example#1
>>> class TEST:
...  pass
...
# example#2
>>> class TEST():
...  pass
Larz60+ wrote Dec-01-2019, 05:36 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
Hi Sarah,

sarah Wrote:Defining parent Class in Python 2.7.11
Don't use python 2.7. Its end of life is scheduled for January 1st, 2020.. Use python 3, otherwise you're going to learn obsolete things and you won't be able to run the code that everybody runs.

sarah Wrote:what is the conventional way to define Parent class is it with () or without ()?

  • In current python 3, the conventional way is without ().
  • In python 2.7, the conventional way is class Test(object): pass
  • The two ways you showed above work in python 2.7 but they define prehistoric "old style classes" that go back to python 1. I'm very nostalgic of python 1 but I wouldn't recommend it to anyone nowadays.
buran and scidam like this post
Quote
#3
Appreciated!!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Call a varaible from class in the parent class Clement_2000 1 510 May-09-2019, 11:14 PM
Last Post: michalmonday
  parent/add and child/div PyMan 1 561 Feb-23-2018, 04:38 PM
Last Post: nilamo
  Converting c++ class to python class panoss 12 4,735 Jul-23-2017, 01:16 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)