We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 51746fb commit 350d3c5Copy full SHA for 350d3c5
1 file changed
codes_in_Aug2025/OOPS/INHERITANCE/class_method.py
@@ -0,0 +1,17 @@
1
+class testing:
2
+ x = 3
3
+ y = 21
4
+ @classmethod
5
+ def show(cls):
6
+ print("The class attribute of x is:", cls.x)
7
+
8
+ def show_y(self):
9
+ print("The instance attribute of y is:", self.y)
10
11
+num = testing()
12
+num.x = 5 # This will not change the class attribute x, but create an instance attribute x
13
+num.y = 37
14
15
+num.show() # This will call the class method and print the class attribute x
16
+num.show_y() # This will call the instance method and print the instance attribute y
17
+testing.show() # This will also call the class method and print the class attribute x
0 commit comments