No results found for the specified position. What do you know about classes in python? Python Intermediate Mock Interview

MockQuestions

Python Intermediate Mock Interview

Question 2 of 16 for our Python Intermediate Mock Interview

Get More Information About Our Python Intermediate Interview Questions

Question 2 of 16

What do you know about classes in python?

This question to test the ability of writing classes in python.

The class is a collection of methods with common objects. It is used in writing libraries and packages in python. It can organize and utilize the code blocks. For example, we can say that a circle is a class. It has some methods such as the area and the circumference. Those two methods have a common object which is the radius. However, the objects might not be common between methods.

To write a class in python you should use the Keyword class, followed by the class name, then a colon(:). After that, the first thing is the constructor. The main objective of a constructor is to initialize(assign values) data members of the class. In python, a class constructor is started by "def init(self, parameters of the class):". Here is an example of a simple class.

class circle:
    def __init__(self,r):
        self.r=r
    def area(self):
        return 3.14*self.r*self.r

After writing class, As in function to use it, you should call it with its parameters.

C=circle(13)

After calling it, Now we can get the area of the circle by this code.

Area=C.area()
print(Area)

You will get the area of the circle with a radius of 13.

Written by on May 17th, 2021

Next Question

How to Answer: What do you know about classes in python?

Advice and answer examples written specifically for a Python Intermediate job interview.

  • 2. What do you know about classes in python?

      This question to test the ability of writing classes in python.

      The class is a collection of methods with common objects. It is used in writing libraries and packages in python. It can organize and utilize the code blocks. For example, we can say that a circle is a class. It has some methods such as the area and the circumference. Those two methods have a common object which is the radius. However, the objects might not be common between methods.

      To write a class in python you should use the Keyword class, followed by the class name, then a colon(:). After that, the first thing is the constructor. The main objective of a constructor is to initialize(assign values) data members of the class. In python, a class constructor is started by "def init(self, parameters of the class):". Here is an example of a simple class.

      class circle:
          def __init__(self,r):
              self.r=r
          def area(self):
              return 3.14*self.r*self.r

      After writing class, As in function to use it, you should call it with its parameters.

      C=circle(13)

      After calling it, Now we can get the area of the circle by this code.

      Area=C.area()
      print(Area)

      You will get the area of the circle with a radius of 13.

      Written by Aiad Asaad on May 17th, 2021