<jupyter_start><jupyter_text>**Python Object Oriented Programming**- In this tutorial, you’ll learn about Object-Oriented Programming (OOP) in Python and its fundamental concept with the help of examples.  **1. Object Oriented Programming**- Python is a multi-paradigm programming language. It supports different programming approaches.- One of the popular approaches to solve a programming problem is by creating objects. This is known as **Object-Oriented Programming (OOP)**.- An object has two characteristics:  - attributes  - behavior- Let's take an example:- A parrot is can be an object,as it has the following properties: - name, age, color as attributes - singing, dancing as behavior- The concept of OOP in Python focuses on creating reusable code. This concept is also known as **DRY (Don't Repeat Yourself)**.- In Python, the concept of OOP follows some basic principles:  **2. Class**- A class is a blueprint for the object.- We can think of class as a sketch of a parrot with labels. It contains all the details about the name, colors, size etc. Based on these descriptions, we can study about the parrot. Here, a parrot is an object.- The example for class of parrot can be :<jupyter_code>class Parrot:
  pass<jupyter_output><empty_output><jupyter_text>- Here, we use the `class` keyword to define an empty class `Parrot`. - From class, we construct **instances**. - An **instance** is a specific object created from a particular class.  **3. Object**- An object (instance) is an instantiation of a class. When class is defined, only the description for the object is defined. Therefore, no memory or storage is allocated.- The example for object of parrot class can be:<jupyter_code>obj = Parrot()<jupyter_output><empty_output><jupyter_text>- Here, `obj` is an object of class `Parrot`.- Suppose we have details of parrots. Now, we are going to show how to build the class and objects of parrots.  **Example 1: Creating Class and Object in Python**<jupyter_code>class Parrot:

    # class attribute
    species = "bird"

    # instance attribute
    def __init__(self, name, age):
        self.name = name
        self.age = age

# instantiate the Parrot class
blu = Parrot("Blu", 10)
woo = Parrot("Woo", 15)

# access the class attributes
print("Blu is a {}".format(blu.__class__.species))
print("Woo is also a {}".format(woo.__class__.species))

# access the instance attributes
print("{} is {} years old".format(blu.name, blu.age))
print("{} is {} years old".format(woo.name, woo.age))<jupyter_output>Blu is a bird
Woo is also a bird
Blu is 10 years old
Woo is 15 years old<jupyter_text>- In the above program, we created a class with the name `Parrot`. Then, we define attributes. The attributes are a characteristic of an object.- These attributes are defined inside the `__init__` method of the class. It is the initializer method that is first run as soon as the object is created.- Then, we create instances of the `Parrot` class. Here, `blu` and `woo` are references (value) to our new objects.- We can access the class attribute using `__class__.species.` Class attributes are the same for all instances of a class. - Similarly, we access the instance attributes using `blu.name` and `blu.age`. However, instance attributes are different for every instance of a class. - To learn more about classes and objects, go to [Python Classes and Objects](https://www.programiz.com/python-programming/class)  **4. Methods**- Methods are functions defined inside the body of a class. They are used to define the behaviors of an object.  **Example 2 : Creating Methods in Python**<jupyter_code>class Parrot:
    
    # instance attributes
    def __init__(self, name, age):
        self.name = name
        self.age = age

    # instance method
    def sing(self, song):
        return "{} sings {}".format(self.name, song)

    def dance(self):
        return "{} is now dancing".format(self.name)

# instantiate the object
blu = Parrot("Blu", 10)

# call our instance methods
print(blu.sing("'Happy'"))
print(blu.dance())<jupyter_output>Blu sings 'Happy'
Blu is now dancing
{'fraction_non_alphanumeric': 0.09117575164996333, 'fraction_numerical': 0.003911024199462234, 'mean_word_length': 4.1471698113207545, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '333319', 'license': 'CC0-1.0', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1118, 'n_words': 554, 'path': 'Python_Object_Oriented_Programming.ipynb', 'repo_name': 'pb111/Python', 'size': '4091'}