Python ProgrammingPython Programming

What is an object in Python?

An object is a program entity that encloses both data and course of actions(procedures). The data contained in an object is known as the object's data attributes. The procedures or a series of actions conducted in a certain order or manner that an object performs are known as methods. An object's methods are functions (a particular procedure for accomplishing or approaching something) that perform operations on the object's data attributes. An object's data attributes are simply variables that reference the data. There can be multiple instances of an object in a program.

A cup is a stronger resemble of an object. Cups can hold tea or coffee, an object can store data in variables. Cups have several functions, which is similar as an object methods. We can use their handle to pick them up. We can touch their surface to tell if whatever is in them is hot or cool. We can even look inside to see if there's anything in the cup.

Objects are the building blocks of an object-oriented program. A program that uses object-oriented technology is basically a collection of objects. Every variable in Python is literally an object. The remarkable point is to find out what kind of object you have in your possession. Integers, Floats, Boolean, Strings, Dictionaries and Lists are all objects in Python.

The built-in function type() returns the class of the object.

x = 10
y = "Yellow"
z = 10.5
l = [10, 20, 30]

Output of above program

<class 'int'>
<class 'str'>
<class 'float'>
<class 'list'>