Hello @zedshaw .
I am now at exercise 41.
While studying phrase drills and searched google for the parts I did not understand at once I found examples of classes with no brackets, with empty brackets and with ‘object’ inside brackets.
I did this code as example wich will work with any of these creations of the class
I am curios to know when I should use these three options?
Or when not to use them?
class MyClass: # works
# or
class MyClass(): # works
#or
class MyClass(object): # works
soon = 50
def __init__(self, real_name, username, age):
self. real_name = real_name
self. username = username
self.age = age
def start_study_python(self, wish, years_ago):
return wish, self.age - years_ago, 'years ago'
def then(self):
return "I was",self.age ,'then'
me = MyClass('Ulf', 'Ulfen', 48)
print(me.start_study_python("I wish I have started to study Python", 24))
print(MyClass.then(me))
print("In two years I will be", me.soon)
me.age = 28
print("I wish I was", me.age, "instead")
Output:
My username is: Ulfen
(‘I wish I have started to study Python’, 24, ‘years ago’)
(‘I was’, 24, ‘then’)
In two years I am 50
I wish I was 28 instead
Found an answer
When I looked at the video for ex42 there was a good explanation for my question.
MyClass:" is the same as "MyClass(object):
At Stack Overflow I also found this:
Python class inherits object
Scroll down a little bit for the "Python 3.x story:"
There it is explained MyClass(): is also the same as MyClass(object):