What keyword is used to define a class in Python?

Prepare for the Computer Science (CS) III Exam. Study with multiple choice questions, detailed explanations, and comprehensive resources. Boost your confidence and ace the exam!

In Python, the keyword used to define a class is "class." This keyword precedes the name of the class and establishes a new class definition. When you declare a class, you're creating a blueprint for objects. This structure allows you to define attributes and methods that will belong to the instances of the class.

For example, when you write class MyClass:, you initiate the definition of MyClass, which can then include instance variables and methods tailored to its functionality. This is a fundamental concept in object-oriented programming, enabling encapsulation and inheritance, which are key principles when working with classes in Python.

Using any of the other keywords presented would not correctly initiate a class definition in Python. "Define" does not exist in Python as a class declaration keyword, "object" refers to an instance of a class rather than a way to create one, and "create" does not serve a functional purpose in this context. Understanding the use of "class" is essential for defining and working with custom objects in Python effectively.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy