Object-oriented programming with Python
This is one of the most important sections in the chapter. The object-oriented programming paradigm revolves around the concept of objects. Objects contain data (in the form of properties) and functions (in the form of procedures, known as methods in Python programming). We will use a lot of these concepts in our projects. Let’s create an integer variable as follows:
>>> a = 10
We can use the built-in type()
method to see the data type of the variable as follows:
>>> type(a) <class 'int'>
We can do this for the other types of values, too, as follows:
>>> type("Hello, World!") <class 'str'> >>> type(3.14) <class 'float'>
This means that everything is an object in Python. An object is a variable of a class data type. These classes could be built-in library classes or user-defined classes. Let’s see a simple example of a...