---
title: "What is meant by class in python?"  
description: "What is meant by class in python?"  
author: "Amrita Bhattacharjee"  
published: 2023-03-28  
updated: 2023-04-20  
canonical: https://www.mindstick.com/forum/157635/what-is-meant-by-class-in-python  
category: "python"  
tags: ["python"]  
reading_time: 3 minutes  

---

# What is meant by class in python?

What is meant by [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) in [python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python)?Give suitable example.

## Replies

### Reply by Aryan Kumar

In Python, a class is a blueprint for creating objects. It defines a set of attributes and methods that are common to all objects of that class. Classes are used to create new instances of objects that share similar characteristics and behavior.

Here is an example of a class in Python:

```python
class Car:
   def __init__(self, make, model, year):
       self.make = make
       self.model = model
       self.year = year
   def description(self):
       print(f"This car is a {self.make} {self.model} from {self.year}.")
my_car = Car("Toyota", "Corolla", 2021)
my_car.description() # Output: "This car is a Toyota Corolla from 2021."
```

Classes are a fundamental concept in object-oriented programming and are used to organize code into reusable, modular units. They allow developers to create new objects that share similar characteristics and behavior, making it easier to manage and maintain complex codebases.

### Reply by Krishnapriya Rajeev

In Python, a class is a blueprint for creating objects, which are instances of the class. It defines a set of attributes and methods that are common to all instances of the class. *Attributes* are variables that store data, and *methods* are functions that operate on the data. These attributes and methods are defined within the class and can be accessed by instances of the class.

For example, a class "Car" might have attributes like "make", "model", and "year", and methods like "start" and "stop". When you create an instance of the "Car" class, you can set the values of the attributes and call the methods on that instance.

Classes in Python also support *inheritance*, which allows you to create a new class that is a modified version of an existing class. The new class inherits all the attributes and methods of the parent class and can override or add new attributes and methods as needed.

Example:

Creating a class called Person. When creating an object in Python, we use the **init**() function to set initial values for its properties or perform any other necessary operations that need to be done during the object's creation. It is shown below:

```plaintext
 class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        print("Hello, my name is " + self.name + " and I am " + str(self.age) + " years old.")
```

Creating an object person1.

```plaintext
person1 = Person("Krish", 21)
person1.greet()   # Output: Hello, my name is Krish and I am 22 years old.
```

Modifying an object property.

```plaintext
person1.age = 22
```

Deleting an object.

```plaintext
del person1
```

Overall, classes in Python provide a way to organize and reuse code and are an essential part of object-oriented programming.


---

Original Source: https://www.mindstick.com/forum/157635/what-is-meant-by-class-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
