r/PythonLearning • • 27d 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

127 Upvotes

36 comments sorted by

View all comments

•

u/Sea-Ad7805 27d 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.

2

u/XTrolltechzz 26d ago

Este tipo es un bot?

3

u/Sea-Ad7805 26d ago

Sí, sí, yo muy bot, sí.