class in python

  • To define a class, you can use ‘class’, a reserved keyword, followed by the classname and a colon. By convention, all classes start in uppercase. For example:
  • A class can be used to define a data type. Although data types included in Python are many and varied, its capacity to include all our information modelling needs is limited.
  • We can see a class as a user defined data type. However this definition is incomplete, it does not consider that a class has associated functions and is not just a data container
  • class Students:
    //To create a class that takes an object:
     class Students(object)

The __init__() method

  • Immediately after creating an instance of the class, you have to call the __init__() function. This function initializes the objects it creates.
  • It takes at least the argument ‘self’, a Python convention, which gives identity to the object being created.


    class Students:
      def __init__(self) :
    class Employees(object):
      def __init__(self, name, rate, hours) :
    //A function used in a class is called a method. Hence, the __init__() function is a method when it is used to initialize classes.