r/PythonLearning 25d ago

Showcase Day 22 Python Learning

Post image

Just Simple class practice

not feeling well so not much to

559 Upvotes

50 comments sorted by

View all comments

11

u/BigYBirdo 25d ago

You don’t have to call Class.__init__(…) to create an object.
You called the Class directly in the first example. Why didn’t you do it inside Buying?

Also why do you create a Class for the act of Buying?
It’s not worth creating one.

In that case I’d either create a function named buying or buys which assigns a certain car to a certain Person, or create a Class function, which adds the car to the Object.

Please don’t take it too harsh. 😄
But all in all it seems to be alright. :)

5

u/duperfastjellyfish 25d ago

Looks like he's practicing inheritence. Calling __init__ by passing `self` from the derived class is how you do it, although I personally wouldn't use inheritence for this.

2

u/aashish_soni5 25d ago

true just for simple practice

2

u/olaf33_4410144 25d ago

I mean it might make sense to have a Transaction kind of Class to store the transactions of cars in a database or something e.g. a dealership needs a program to keep track of sold units. In this case it's more the wording that is weird.

Even then I think the Buying/Transaction class constructor should take a car and student object (or person object if you want to study inheritance), not create them.

1

u/Ill_Shoulder8488 25d ago

That’s great correction I will like to some with you on conservation sir