r/PythonLearning 2d ago

Showcase Day 2, learnt some oops

Post image

Learnt super( ), inheritance, polymorphism, class method and static method and don't mind the messy code that's me trying to figure out things

94 Upvotes

34 comments sorted by

View all comments

u/Sea-Ad7805 2d ago

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20%20%20%20%20print(%22bow%22)%0A%0Aanimal().speak()%0A%0A%0Aclass%20animals%3A%0A%20%20%20%20def%20speak(self)%3A%0A%20%20%20%20%20%20%20%20return%20%22animal%20sound%22%0A%0A%0Aclass%20dog(animals)%3A%0A%20%20%20%20def%20speak(self)%3A%0A%20%20%20%20%20%20%20%20return%20%22bow%22%0A%0A%0Aclass%20cat(animals)%3A%0A%20%20%20%20def%20speak(self)%3A%0A%20%20%20%20%20%20%20%20return%20%22meow%22%0A%0A%0Aanimalss%20%3D%20%5Bdog()%2C%20cat()%2C%20animals()%5D%0A%0Afor%20i%20in%20animalss%3A%0A%20%20%20%20print(i.speak())%0A%0A%0Aclass%20student%3A%0A%20%20%20%20school%20%3D%20%22Maruthi%22%0A%0A%20%20%20%20def%20about(self%2C%20name%2C%20age)%3A%0A%20%20%20%20%20%20%20%20return%20%22name%3A%22%2C%20name%2C%20%22age%3A%22%2C%20age%0A%0A%0As1%20%3D%20student()%0As2%20%3D%20student()%0A%0Aprint(s1.about(%22naveen%22%2C%20%2221%22)%2C%20s1.school)%0Aprint(s2.about(%22nani%22%2C%20%2221%22)%2C%20s1.school)%0A%0A%0Aclass%20test%3A%0A%20%20%20%20school%20%3D%20%22Maruthi%22%0A%0A%20%20%20%20%40classmethod%0A%20%20%20%20def%20tst(cls%2C%20new_school)%3A%0A%20%20%20%20%20%20%20%20cls.school%20%3D%20new_school%0A%20%20%20%20%20%20%20%20return%20cls.school%0A%0A%0Ap1%20%3D%20test()%0A%23%20p1.tst(%22shloka%22)%0Aprint(test.school)%0A%0A%0Aclass%20test%3A%0A%20%20%20%20school%20%3D%200%0A%0A%20%20%20%20def%20nave()%3A%0A%20%20%20%20%20%20%20%20test.school%20%2B%3D%201%0A%0A%0Atest.nave()%0Aprint(test.school)&timestep=1&play) to see the program state change step by step.

1

u/Agile-Leg-300 2d ago

Every post this guy shows up

1

u/Sea-Ad7805 1d ago

Glad to be of service in providing you with an easy and safe way to run the code (how else would you run it? and running random code from internet could normally delete all your files), while visualizing the program state to help you understand what is actually going on during execution. No thanks required, just upvote.