-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ88.py
More file actions
20 lines (19 loc) · 708 Bytes
/
Copy pathQ88.py
File metadata and controls
20 lines (19 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class MyClass:
class_variable = "I am a class variable"
def __init__(self, name):
self.name = name
def instance_method(self):
print(f"Hello, {self.name}! I can access the instance variable and class variable.")
print(f"Class Variable: {self.class_variable}")
@classmethod
def class_method(cls):
print(f"Hello! I am a class method. I can access the class variable: {cls.class_variable}")
@staticmethod
def static_method():
print("Hello! I am a static method. I cannot access instance or class variables.")
obj = MyClass("Alice")
obj.instance_method()
obj.class_method()
obj.static_method()
MyClass.class_method()
MyClass.static_method()