> For the complete documentation index, see [llms.txt](https://gchandra.gitbook.io/big-data-and-tools-with-nosql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gchandra.gitbook.io/big-data-and-tools-with-nosql/python/python-classes.md).

# Python Classes

**Classes** are templates used to define the properties and methods of objects in code. They can describe the kinds of data the class holds and how a programmer interacts with them.

**Attributes - Properties**

**Methods - Action**

<figure><img src="https://1471795080-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrtXPLjVTxuTGIysjCx89%2Fuploads%2FEYgw6nSCeonYod9873wF%2Fimage.png?alt=media&amp;token=6e129ff3-45fb-465e-aa59-bc6cb2a7e7a2" alt=""><figcaption><p>Img Src: <a href="https://www.datacamp.com/tutorial/python-classes">https://www.datacamp.com/tutorial/python-classes</a></p></figcaption></figure>

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

    def bark(self):
        print(f"{self.name} says woof! and its {self.age} years old")

my_dog = Dog("Buddy", 2)

my_dog.bark()
```

* **Class Definition**: We start with the `class` keyword followed by `Dog`, the name of our class. This is the blueprint for creating `Dog` objects.
* **Constructor Method (`__init__`)**: This particular method is called automatically when a new `Dog` object is created. It initializes the object's attributes. In this case, each `Dog` has a `name` and an `age`. The `self` parameter is a reference to the current instance of the class.
* **Attribute**: `self.name` and `self.age` These are attributes of the class. These variables are associated with each class instance, holding the specific data.
* **Method**: `bark` It is a method of the class. It's a function that all `Dog` instances can perform. When called, it prints a message indicating that the dog is barking.

**Python supports two types of methods within classes.**

* StaticMethod
* InstanceMethod

```
git clone https://github.com/gchandra10/python_classes_demo.git
```
