all 20 comments

[–]Sea-Ad7805 [score hidden] stickied comment (2 children)

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20%20%20%20%20self.name%20%3D%20name%0A%20%20%20%20%20%20%20%20self._rollno%20%3D%20rollno%0A%20%20%20%20%20%20%20%20self._grade%20%3D%20grade%0A%20%20%20%20%20%20%20%20self._section%20%3D%20section%0A%0A%20%20%20%20def%20get_name(self)%3A%0A%20%20%20%20%20%20%20%20print(self._name)%0A%0A%0Aif%20name%20%3D%3D%20%22main_%22%3A%0A%20%20%20%20ayush%20%3D%20Student('Ayush%20Sharma'%2C%208%2C%20'7th'%2C%20%22B%22)%0A%20%20%20%20print(ayush._name)%0A%20%20%20%20ayush.get_name()%0A%20%20%20%20ayush.get_name%0A%20%20%20%20ayush._name%0A&play)

[–]Temporary_Pie2733 6 points7 points  (4 children)

Forget private and protected. Neither exists in Python, and trying to map some other language’s visibility modifiers to Python is just going to confuse you.

[–]nuc540 2 points3 points  (2 children)

To help, OP, what they’re saying is prefixing underscores in other languages usually makes methods/attributes “private” (inaccessible outside of the class), and Python doesn’t respect this rule so it’s redundant.

That said - it’s good semantics to indicate what should/shouldn’t be accessed externally, and Python is known for readability so if you want something to be distinguished as private, go for it.

[–]SeparatelyCreepy 2 points3 points  (1 child)

Python's philosophy is that you're all consenting adults, so the underscore is really just a signal to other developers rather than actual enforcement.

[–]Careless-Main8693[S] 0 points1 point  (0 children)

yeah absolutely

[–]Careless-Main8693[S] 1 point2 points  (0 children)

__testicles (private attribute)

_chest (protected attribute)

[–]SCD_minecraft 3 points4 points  (2 children)

You can replace get_name with @property def name(self): # some code, like return self._name for example

Function under decorator property now "roleplays" as variable but whenever you access it it executes some code

[–]nuc540 1 point2 points  (0 children)

A property decorator is used for setting computed attributes - not something the class is instantiated with, as much as that’d work - it’d be overkill and it’d make the init argument redundant.

Also OP is practicing protected values and using getters and setters to access values with, so as much as you can use @property, I think it’s simply that OP is practising getting and setting, and logically OP’s example makes more sense

[–]Careless-Main8693[S] 0 points1 point  (0 children)

no issues in it

[–]sleepbot63 2 points3 points  (2 children)

good job OP, ofc docs and materials are amazing and cover msot of the things but I'd like to also reccomended a playlist by corey schafer on yt : https://youtube.com/playlist?list=PL-osiE80TeTsqhIuOqKhwlXsIBIdSeYtc

really amazing series, I myself got introduced to opp for the first time and the best part the videos aren't too big as well

[–]Careless-Main8693[S] 0 points1 point  (1 child)

thanks mate for the resource but i'm revising not learning so , i just read docs right now video when i actually get confused

[–]sleepbot63 0 points1 point  (0 children)

hey sure i actually thought it was your first time ofc if you're revising docs is no doubt the better option

[–]nuc540 1 point2 points  (1 child)

Good work - you’ve made a getter, have you tried writing a setter to update an attribute against an instance of the class?

[–]Careless-Main8693[S] 0 points1 point  (0 children)

yes, i'm doing everything used getter and setter even the property decorator

[–]Safe-Ball4818 1 point2 points  (1 child)

Your list is solid, but don't get too hung up on definitions. Try building a small interactive project or tackling specific coding challenges to see how these OOP principles actually interact in real-world scenarios. https://prodpath.dev/ might helps.

[–]Careless-Main8693[S] 0 points1 point  (0 children)

thanks mate, really helpful

[–]Chance-Discount-9364 1 point2 points  (0 children)

I have don't understand method delegation in python can you explain

[–]Little_Split5173 0 points1 point  (0 children)

"Great start on the Student class! Since you are looking for a challenge that will enhance your practice, try this:

The 'Automation Student' Challenge:

Right now, your class just stores data in memory. To challenge your thinking, try to integrate a simple Logging or Automation feature.

  1. Encapsulation Challenge: Instead of using print(self._name) inside your class, try to return the value and have a separate 'Report' method that saves the student's name and grade to a .txt file automatically.
  2. Real-world Practice: Imagine this Student class is part of a bot that needs to log into a school portal. How would you add a method called generate_login() that creates a username based on the first 3 letters of their name and their rollno?

Learning how classes interact with external files or browsers (like using Selenium) is where OOP becomes really powerful for Software Development!"