---
# System prepended metadata

title: ' OOPS - 1'

---

---
title: Python-2 Module Introduction 
description: 
duration: 900
card_type: cue_card
---

# Python-2 Module Introduction

<span style="background-color: pink;">**Ice-breaking**</span> 

Hey Everyone, welcome to your first session of the Python-2 module.

I hope you have a great time learning and interacting here. To get to know each other better, let's start with a quick introduction! Please share two lines about yourself in the chat.

Alright, to begin, let me introduce myself. My name is [Your Name], and [brief introduction about yourself and experience]. <font color='red'>**Display & Share your LinkedIn profile with the learners.**</font>

I'm here to guide you on your learning journey at Scaler. I'll be closely monitoring your progress, and if I see any areas needing improvement, I'll reach out to you to understand the challenges.

However, remember, open communication is key! Don't hesitate to reach out (via Slack/WhatsApp DM) if anything troubles you, big or small. We're here to support you and help you succeed! Let's work together to avoid any dips in your performance.

Now that we've gotten to know each other a bit, let's dive into the Python-2 module!

### <font color='purple'>**Module Importance**</font>

- In data science and machine learning domain, Python is a powerful language that comes in handy for handling almost every task.
- Understanding Python is crucial for data analysts/scientists to manipulate vast and diverse datasets proficiently, perform complex computations, filter information, and build scalable applications.
- This module equips you with the ability to handle complex data types and learn modularized ways of writing code, working with exceptions, handling real-time data from websites and drawing crucial information from raw data.
- It also provides you exposure to the advanced Python concepts that build as a layer over your fundamental understanding of the Python-1 module.

#### <font color='red'>**Instructor Note:**</font>
       
- Perform a brief Google search on essential skills for data analysts/scientists, emphasizing the importance of Python. 
- Highlight that mastering Python will benefit the learner in other related modules as well, such as DAV, ML, NLP, CV.

**Example JDs:**

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/066/754/original/Screen_Shot_2024-02-29_at_15.47.16_PM.png?1709201851" width="600" height="600">

### <font color='purple'>**Module Overview**</font>

Below, you’ll find a comprehensive breakdown of the lectures:

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/067/421/original/Python-2_flowchart.png?1709749731" width="600" height="500">

At the end of this module, there will be a <font color='red'>**MODULE TEST**</font> designed to evaluate and solidify your acquired skills.

### <font color='purple'>Module Expectation</font>

* This module explores advanced Python topics such as modular programming, object-oriented programming (OOP), web scraping, and version control.
* Completion of this module doesn't instantly make you a Python expert, but it lays a solid foundation for further learning.
* Python is a powerful programming language with endless possibilities, and there's always more to discover beyond the scope of this course.
* Engaging in hands-on exercises and real-world projects is crucial for developing proficiency in Python.

### <font color='purple'>Attendance</font>

* Try to maintain at least **75% attendance** either through live classes or by watching recordings.
* However, I recommend you attend classes regularly because otherwise, it may create backlogs.
* So, I expect all of you to attend live classes and if you are unable to, please send me a message stating the reason.

### <font color='purple'>Assessments & PSP</font>

This module covers every advanced Python concept spread across 9 comprehensive lectures.

Sharpen your skills with solving assessments:
- **5 assignment questions** per lecture
- **3-5 homework questions** per lecture (optional)

**Aim for a high PSP score (85+):**
- **PSP (Problem Solving Percentage)** - Solved Assignment Problems / Total Open Assignment Problems
- Demonstrates your expertise in advanced Python, a valuable asset for your resume and interviews.
- Not just for academic success, but it prepares you for real-world applications as well.

We'd like to clarify that your **PSP is calculated solely based on your performance on assignment problems**. Homework problems do not contribute to your PSP. 

However, once you're done with the assignments, we strongly recommend completing the homework for further practice. 

**Remember:**
- Seek help: Reach out to instructors or TAs for guidance.
- Track progress: Monitor PSP scores and adjust learning strategies accordingly.

### <font color='purple'>Post-lecture Content
</font>

- We encourage you to regularly access **post-lecture content** via the dashboard.
- You’ll receive a comprehensive **cheat sheet** as well at the end of the module.

### <font color='purple'> Module Test & Mock Interview</font>

- **At the module's end**, there will be **module test** and **mock interview** accessible through the dashboard.
- Module test/re-test is **90 minutes** long, with all learners eligible to take both tests, which include **MCQs and Coding questions**. 
- Test launch dates will be provided at the module's end, and it's crucial for all learners to participate, aiming to pass the cutoff of **70 out of 100**.
- After completing the module test, learners can book a mock interview immediately to receive feedback from Industry Experts.
- The next module will start in parallel with the module tests and mock interviews.

### <font color='purple'>Placement Eligibility</font>

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/068/073/original/Screen_Shot_2024-03-14_at_11.51.49_AM.png?1710398122" width="500" height="300">

To become eligible for job placements, successful completion of all the following is required:
1. SQL module - Module Test + Mock Interview
2. Tableau & Excel module - Module Test
3. Python 1 & 2 modules - Module Test

Completing each of these components is crucial for your eligibility in job placements, and failing to complete either one will impede your qualification for placements.

#### <font color='red'>Ready to master advanced Python? Let's get started!</font>

---
title: Agenda
description:
duration: 300
card_type: cue_card
---

# OOPS 1 - Introduction

### Agenda

* OOP - Object Oriented Programming
* Classes & Objects
    * Defining a class
    * Instantiating an object
* 4 Pillars of OOP
    * Abstraction
    * Encapsulation
    * Inheritance
    * Ploymorphism
* Constructors
* Class & Instance Variables

---
title: Understanding OOP
description:
duration: 1200
card_type: cue_card
---

### Object Oriented Programming (OOP)

- It is a programming paradigm.
  - Paradigm means the way of writing a program, fixed set of practices.

- In OOP, we have *classes* and *objects*.
- **Class** is a blue print that defines the *methods* and *properties* of an **Object**.

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/015/843/original/Screenshot_2022-10-06_at_8.53.31_AM.png?1665026595">


Code
```python=
class Student:
  # methods
  # properties
  pass

  # pass represents empty body in Python
```

Code
```python=
isinstance(Student, object)
```

> Output

    True

Code
```python=
# create an instance of this class - instantiate - create an object of class type
a = Student()
```

Code
```python=
type(a)
```

> Output

    __main__.Student

Code
```python=
isinstance(a, Student)
```

> Output

    True

Code
```python=
isinstance(a, object)
```

> Output

    True

In Python, everything is an object.

---
title: Quiz-1
description: Quiz-1
duration: 60
card_type: quiz_card
---

# Question

What is the main concept behind Object-Oriented Programming (OOP)?

# Choices

- [ ] Writing code that is easy to debug.
- [ ] Using functions and procedures to perform operations.
- [x] Organizing code into objects and classes.
- [ ] Speeding up the execution time of programs.

---
title: 4 Pillars of OOP
description:
duration: 1200
card_type: cue_card
---

### 4 Pillars of OOP

1. #### ***Encapsulation***: Putting things together
2. #### ***Abstraction***: Hiding the irrelevant features    
    <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/015/844/original/Screenshot_2022-10-06_at_9.11.35_AM.png?1665027689">
3. #### ***Inheritance***: objetcs of one class can inherit the features of other class 
    <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/015/845/original/Screenshot_2022-10-06_at_9.11.44_AM.png?1665027716">
4. #### ***Polymorphism***: Same entity but different behaviour

Code
```python=
# Examples of Polymorphism

print(56 + 75)

print("what" + "on" + "earth")
```

> Output

    131
    whatonearth

When you call a class, it creates an object of that class.

Code
```python=
s1 = Student()

s1
```

> Output

    <__main__.Student at 0x79f6fc1e8bb0>

Code
```python=
# Making property of s1

s1.name = "Bipin"

s1.name
```

> Output

    'Bipin'

Code
```python=
s2 = s1

s2.name
```

> Output

    'Bipin'

---
title: Quiz-2
description: Quiz-2
duration: 60
card_type: quiz_card
---

# Question

In Python, how do you define a new class named `MyClass`?

# Choices

- [ ] `def MyClass():`
- [x] `class MyClass:`
- [ ] `new MyClass():`
- [ ] `MyClass = Class.new()`

---
title: Break & Doubt Resolution
description:
duration: 600
card_type: cue_card
---

### Break & Doubt Resolution

`Instructor Note:`
* Kindly take this time (up to 5-10 mins) to give a short break to the learners.
* Meanwhile, you can ask the them to share their doubts (if any) regarding the topics covered so far.

---
title: Constructors
description:
duration: 1200
card_type: cue_card
---

## Constructors

- Constructor is function which is called whenever an object is created, to allocate the memory to that object.
- In Python, we don't have direct access to constructor.

> **Note:** `__init__()` method is not a constructor. It's an initializing function.

### Life Cycle of an Object

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/015/846/original/Screenshot_2022-10-06_at_9.24.23_AM.png?1665028448">

\
Code
```python=
class Student:
    def hello():
        print("Hello!")

s2 = Student()

s2.hello()
```

> Output

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-16-3ef1267b0b84> in <cell line: 1>()
    ----> 1 s2.hello()
          2 # by default python passes an argument known as self

    TypeError: Student.hello() takes 0 positional arguments but 1 was given

#### By default, Python passes an argument known as `self`.

Code
```python=
# We can name anything to self, here giving random_variable_name.

class Student:
    def hello(random_variable_name):
        print("Hello!")
        print(id(random_variable_name))
```

Code
```python=
s1 = Student()

s1.hello()
# Student.hello(s1)

print(id(s1))
```

> Output

    Hello!
    134101698776656
    134101698776656

> **Note:** `self` argument is reference of the object itself. 
In the above example, we get same id because both times, it is the same object.

Implicitly, Python already has a standard init function. 

But you can create a custom `__init__` function as well. It will override.

Code
```python=
class Student:
    def __init__(self, name, age):
        self.name = name
        # This will create property name on current object `self`
        self.age = age

    def study(self):
      print("lemme watch movie")
```

Also, `self` is automatically passed in Python.

Code
```python=
s1 = Student("Vaishali", 5000)

print(s1.name, s1.age)
```

> Output

    Vaishali 5000

Code
```python=
s2 = Student("Vinoth", 10000)

print(s2.name, s2.age)
```

> Output

    Vinoth 10000

---
title: Class and Instance Variables
description:
duration: 1200
card_type: cue_card
---

#### Class variable - A variable that is shared among all instances of a class.

#### Instance variable - A variable that is unique to each instance of a class.

Code
```python=
class Dog:
    kind = "canine" # class variable

    def __init__(self, name):
        self.name = name # object / instance variable 
```

Code
```python=
d1 = Dog("tuffy")
d2 = Dog("scooby")
```

Code
```python=
d1.name, d2.name
```

> Output

    ('tuffy', 'scooby')

Code
```python=
d1.kind, d2.kind
```

> Output

    ('canine', 'canine')

Code
```python=
# Accessing a class variable
Dog.kind
```

> Output

    'canine'

Code
```python=
Dog.name 
```

    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-31-f175d70793be> in <cell line: 1>()
    ----> 1 Dog.name #error

    AttributeError: type object 'Dog' has no attribute 'name'

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/016/213/original/Screenshot_2022-10-12_at_9.34.55_AM.png?1665547478">

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/016/214/original/Screenshot_2022-10-12_at_9.35.04_AM.png?1665547506">

\
Code
```python=
# Changing the class variable through an object d1
d1.kind = "doberman"
```

Code
```python=
# Creates an instance/object variable just for that object
d1.kind
```

> Output

    'doberman'

Code
```python=
d2.kind
```

> Output

    'random_kind'

Code
```python=
Dog.kind = "random_kind"
print(Dog.kind)
```

> Output

    random_kind

Code
```python=
print(d1.kind)
print(d2.kind)
```

> Output

    doberman
    random_kind

Code
```python=
d1 = Dog("tuffy")
d2 = Dog("scooby")
```

Code
```python=
d1.kind
```

> Output

    'random_kind'

Code
```python=
d2.kind
```

> Output

    'random_kind'

---
title: Quiz-3
description: Quiz-3
duration: 60
card_type: quiz_card
---

# Question

What will be the output of the following piece of code?

Code
```python=
class Student:
    name = "Bipin"
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def hello(self):
      print(f"Hello {self.name}")

bipin = Student("Ayush", 20)
bipin.hello()
```

# Choices

- [x] Hello Ayush
- [ ] Hello Bipin
- [ ] Error
- [ ] None of the above

---
title: Revisiting Concepts
description:
duration: 1200
card_type: cue_card
---

Code
```python=
class Student:
    def hello(self):
        print("hello!")

s1 = Student()

Student.hello(s1)
s1.hello()
```

> Output

    hello!
    hello!
    
When updating a class variable using an object -
- In case of immutable - New Instance Variable is created
- In case of mutable - Original Class Variable is updated

Code
```python=
class Dog:
    tricks = []

    def __init__(self, name):
        self.name = name

    def teach_trick(self, trick):
        self.tricks.append(trick)
```

Code
```python=
d1 = Dog("pupy")
d2 = Dog("tommy")
```

Code
```python=
print(d1.tricks)
print(d2.tricks)
```

> Output

    []
    []

Code
```python=
print(d1.name)
print(d2.name)
```

> Output

    pupy
    tommy

Code
```python=
d1.teach_trick("jump")
```

Code
```python=
d1.tricks
```

> Output

    ['jump']

Code
```python=
d2.tricks
```

> Output

    ['jump']

#### <span style="color: red;">**Instructor Note:**</span> 

Share these instructions and ref video link with the learners.

Instructions to access the post-lecture notes : 
1. Click on the **.ipynb file** available on your dashboard.
2. When a webpage with the markdown opens, **Right Click** and **Save As**.
3. Save the file onto your local system with an **.ipynb extension**.
4. Try opening the file via **Jupyter Notebook** or **Google Colab**.

**Reference Video -** [**link**](https://www.loom.com/share/299766495f264f9798eef43e024e6d66?sid=d4cc00e7-df53-4428-992c-4124130a5b8e)

---
title: Quiz-4
description: Quiz-4
duration: 60
card_type: quiz_card
---

# Question

What will be the output of the following code snippet?

Code
```python=
class Calculator:
    def __init__(self, number):
        self.number = number

    def multiply_by_two(self):
        return self.number * 2

calc = Calculator(3)
print(calc.multiply_by_two())
```

# Choices

- [ ] 3
- [x] 6
- [ ] Calculator
- [ ] Error

---
title: Practice Coding Question(s)
description: 
duration: 600
card_type: cue_card
---

### Practice Coding Question(s)

You can pick the following question and solve it during the lecture itself.

This will help the learners to get familiar with the problem solving process and motivate them to solve the assignments.

<span style="background-color: pink;">Make sure to start the doubt session before you start solving the question.</span>

Q. https://www.scaler.com/hire/test/problem/96309/