Python class Keyword
Python is an object-oriented programming language and it allows to create objects. In order to create an object, first of all, object should be defined in the program. The Python class keyword is used to define a new object type. Within a class, object's methods and properties are defined and when an object is created, its methods and properties are determined by the class in which it is created.
#defining new object type class class_name: statements #creating an object MyObject = cleass_name()
In the below example, a class (new object type) called circle and object of this class called MyCircle are created. MyCircle has only one property radius which is defined in class circle. Please check the syntax for accessing object property inside program.
class circle: radius = 10 MyCircle = circle() print(MyCircle.radius)
The output of the above code will be:
❮ Python Keywords