What keyword is used to define a class in Python?

Master Python with the PCAP Certification! Explore interactive quizzes and detailed explanations to ensure your exam success. Gain confidence and get certified!

In Python, the keyword used to define a class is "class." When you want to create a new class, you begin with the keyword "class" followed by the name of the class and a colon. This signifies to the Python interpreter that a class is being defined. Classes are essential for creating objects in Python, which encapsulate data and functionality together.

For example, defining a simple class in Python would look like this:


class MyClass:

def my_method(self):

print("Hello, World!")

This correct usage of the keyword "class" indicates that you are setting up a new blueprint from which objects can be instantiated.

The other options do not serve this purpose: "def" is used to define functions, not classes; "object" refers to an instance of a class and is not a keyword for defining a class; and "module" refers to a file containing Python code that can define functions, classes, and variables but is not synonymous with the creation of a class. Thus, "class" is the only appropriate keyword for this specific task in Python.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy