-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNOTES-classAndObject
More file actions
18 lines (15 loc) · 1007 Bytes
/
NOTES-classAndObject
File metadata and controls
18 lines (15 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#In Python, a class is a blueprint or a template for creating objects, which are instances of the class. A class defines the attributes (data) and methods (functions) that its objects will have.
#To define a class in Python, you use the class keyword followed by the class name. For example:
class MyClass:
def __init__(self, arg1, arg2):
self.arg1 = arg1
self.arg2 = arg2
def my_method(self):
# do something
#This creates a class called MyClass with an __init__ method (a special method that gets called when an object is created) that takes two arguments, and a my_method method.
To create an object of this class, you use the class name followed by parentheses, like this:
my_object = MyClass("arg1 value", "arg2 value")
#This creates an instance of the MyClass class with arg1 and arg2 attributes set to the values passed in.
#You can then access the attributes and call methods on the object using dot notation, like this:
print(my_object.arg1)
my_object.my_method()