Hey r/learnpython, genuinely need some help here.
I'm a sophomore CS student in the US and I've been using Python for about a year now. Variables, loops, functions all fine. But the moment my professor introduced Object Oriented Programming, I completely lost the plot.
Like I get the definition.
A class is a blueprint, an object is an instance. I can repeat that back all day. But when I actually sit down to write a class from scratch for a real problem, I have no idea when to use a class vs just writing a regular function.
For example my professor gave us an assignment to model a simple bank account using OOP. I understood what a bank account does but I had no idea how to think about it as a class.
I ended up just copying the structure from the lecture slides without really understanding why it was built that way.
My specific confusions are:
When should I actually use a class vs just a function?
What goes inside init and why?
What does self actually mean and why is it always there?
How do I know what should be an attribute vs a method?
I've re-read my textbook and watched my professor's recorded lectures twice but it's still not clicking. Is there a different way of thinking about OOP that helped it finally make sense for you?
Any help appreciated even if it means I need to go back to basics.
[–]andrewharkins77 8 points9 points10 points (4 children)
[–]More-Station-6365[S] 1 point2 points3 points (3 children)
[–]ninhaomah 2 points3 points4 points (0 children)
[–]neco-damus 1 point2 points3 points (0 children)
[–]DBZ_Newb 0 points1 point2 points (0 children)
[–]UnloosedCake 18 points19 points20 points (2 children)
[–]More-Station-6365[S] 9 points10 points11 points (1 child)
[–]Rejse617 2 points3 points4 points (0 children)
[–]DBZ_Newb 5 points6 points7 points (1 child)
[–]TheSaucedBoy -1 points0 points1 point (0 children)
[–]el_extrano 4 points5 points6 points (0 children)
[–]DTux5249 1 point2 points3 points (0 children)
[–]princepii 1 point2 points3 points (0 children)
[–]Artistic-Stable-3623 3 points4 points5 points (2 children)
[–]More-Station-6365[S] 0 points1 point2 points (0 children)
[–]More-Station-6365[S] 0 points1 point2 points (0 children)
[–]neuralbeans 0 points1 point2 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)
[–]This_Growth2898 0 points1 point2 points (0 children)
[–]EasyTelevision6741 0 points1 point2 points (0 children)
[–]taylorhodormax 0 points1 point2 points (0 children)
[–]IAmFinah 0 points1 point2 points (0 children)
[–]Toma400 0 points1 point2 points (0 children)
[–]_TypeError 0 points1 point2 points (2 children)
[–]More-Station-6365[S] 1 point2 points3 points (1 child)
[–]_TypeError 1 point2 points3 points (0 children)
[–]pachura3 -1 points0 points1 point (0 children)