Learn practical skills, build real-world projects, and advance your career
Created 3 years ago
Python Classes/Objects
Python is an object oriented programming language.
Almost everything in Python is an object, with its properties and methods.
A Class is like an object constructor, or a "blueprint" for creating objects.
Create a Class
To create a class, use the keyword class:
class MyClass:
x = 5
print(MyClass)
<class '__main__.MyClass'>
Create Object
Now we can use the class named MyClass to create objects:
p1 = MyClass()
print(p1.x)
5