Python Program To Create Bankaccount Class With Deposit
Python Program To Create Bankaccount Class With Deposit
First of all, define class Bankacccount. This step is followed by defining a function using __init__. It is run as soon as an
object of a class is instantiated. This __init__ method is useful to do any initialization you want to do with object, then we
have the default argument self.
# BankAccount class
class Bankaccount:
def __init__(self):
This step is followed by declaring that balance is 0 using self argument then we simply print a statement welcoming to
Machine. In function deposit and withdraw , amount is taken as input(in float) and is then added/subtracted to the balance.
Thus resultant balance is printed in next line.
def deposit(self):
amount = float(input("Enter amount to be deposited: "))
self.balance += amount
print("\n Amount Deposited:", amount)
s = Bank_Account()
# Calling functions with that class object
s.deposit()
s.withdraw()
s.display()
Output:
Hello !!! Welcome to Deposit&Withdrawal Machine