Skip to content

Commit 350d3c5

Browse files
authored
Add files via upload
1 parent 51746fb commit 350d3c5

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)