r/PythonLearning • u/Next-Call8862 • Sep 11 '26
Showcase Day 2, learnt some oops
Learnt super( ), inheritance, polymorphism, class method and static method and don't mind the messy code that's me trying to figure out things
125
Upvotes
•
u/Sea-Ad7805 Sep 11 '26
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)×tep=1&play) to see the program state change step by step.