Python is an object-oriented programming language. Almost everything in Python is an object, with its properties and methods.
To create objects, we use a Class. A Class is like an object constructor, or a "blueprint" for creating objects.
To create a class in Python, use the keyword class.
class MyClass: x = 5print(MyClass)
Now we can use the class named MyClass to create objects. An object is a specific instance of a class.
// Create an object named p1, and print the value of x: class MyClass: x = 5p1 = MyClass() print(p1.x)
You can create as many objects as you want from a single class. Each object is independent of the others.
class Car: wheels = 4// Create two separate Car objects car1 = Car() car2 = Car()
print("Car 1 wheels:", car1.wheels) print("Car 2 wheels:", car2.wheels)
pass StatementClass definitions cannot be empty. If you need to create a class with no content (perhaps as a placeholder for future code), use the pass statement to avoid getting an error.
class EmptyClass: pass
Which keyword is used to create a class in Python?