Classes, objects, and object-oriented programming

Classes are collections of methods and attributes. Briefly, attributes are variables of the object (for example, each instance of the Employee class has its own name, age, salary, and benefits; all of them are attributes).

Methods are simply functions that modify attributes (for example, to set the employee name, to set his/her age, and also to read this information from a database or from a CSV list). To create a class, use the class keyword.

In the following example, we will create a class for an incrementer. The purpose of this object is to keep track of the value of an integer and eventually increase it by 1:

class Incrementer(object):  def __init__(self):  print ("Hello world, I'm the ...

Get Python Data Science Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.