Python Objects and Class

In this section we will learn about the objects in Python. We will demonstrate how to create objects and access them in Python programming. The Python programming is an object oriented programming language that has its main focun on objects rather than on functions.

An object in Python is considered to be only variables or data and the functions that are to be performed on that variables or data.


Defining a Class in Python

A class can be created in Python by using the class keyword. After the keyword class we write the name of the class and end the statement with a colon.

Consider the following example in which a class is defined:


>>> class NewClass:


The above class has created a new local namespace in which all the attributes of the class will be defined. The attributes can be variables or data or functions or methods.


Creating an Object in Python

A class in Python can be used to access the different attributes. We can also create new objects using class. An object can be created very easily similar to when a function is defined. Consider the following example in which an object is created:

>>> obj = NewClass()