Python Classroom Notes – 28/April/2024

Object Oriented Programming using Python

  • Refer Here for basics of OOP

  • Basic constructs of OOP

    • class
    • object
    • attributes/members
    • methods
  • objects represent litrerally anything (few examples below)

    • bank account
    • car
    • engine
    • movie
    • theatre
    • transcation
  • object will have contents and charecteristics

    • laptop:
      • contents: (What it has) => members
        • cpu
        • ram
        • disk
        • monitor
        • keyboard
      • charecteristics: (What it does) => methods
        • started
        • stopped
        • browse
        • run applications
    • bank account
      • contents: (What it has) => members
        • id
        • name
        • address
        • mobile
        • email
        • balance
        • type
      • characteristics: => methods
        • deposit
        • withdraw
        • close
  • Class: This is a design/template of object, we use class to create objects.

  • Easiest way to represnt classes is uml diagram Refer Here

  • oop in python

  • Refer Here for basic oop in python

Problem 1:

  • Lets create a demonstration of Bank Account
"""
This module will have Bank Account class
"""

class BankAccount:
    """
    This class will have basic Bank Account Functionality
    """
    def __init__(self, account_number:str,name:str, initial_deposit:float = 0) -> None:
        """
        This method initializes the object with initial values
        """
        self.account_number = account_number
        self.name = name
        self.balance = initial_deposit

    def withdraw(self, amount):
        """
        This method withdraw amount
        """
        self.balance -= amount

    def deposit(self, amount):
        """
        This method deposits amount
        """
        self.balance += amount
  • Debug the account creation, deposits and withdrawls. Always print the balance
  • Refer Here for the project structure.

Objects: Inheritence (is-a), composition (has-a)

  • Refer Here for tutorial on Inheritance and composition

Problem 2

  • We have two types of bank accounts
    • savings account
      • donot allow deposits more than 1 Million or 10 lakhs
      • dont allow negativ balance
    • Current account
      • allow deposits of any amount
      • allow negative balance
  • Refer Here for changes

Problem 3

  • Create Student and Course implemenation according to any institute and design classes. Refer Here for changes
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Plugin for Social Media by Acurax Wordpress Design Studio

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%