d. Create a python class called BankAccount that has a class member variable called interest_rate with default value set to 0.05, and 3 member variables name, number, and balance code example
Example 1: python class
class Dog(object):
def __init__(self, name, age):
self.name = name
self.age = age
def speak(self):
print("Hi I'm ", self.name, 'and I am', self.age, 'Years Old')
JUB0T = Dog('JUB0T', 55)
Friend = Dog('Doge', 10)
JUB0T.speak()
Friend.speak()
Example 2: class python 3
A class is a block of code that holds various functions. Because they
are located inside a class they are named methods but mean the samne
thing. In addition variables that are stored inside a class are named
attributes. The point of a class is to call the class later allowing you
to access as many functions or (methods) as you would like with the same
class name. These methods are grouped together under one class name due
to them working in association with eachother in some way.
#example
# To create a simple class:
class Shape:
def __init__():
print("A new shape has been created!")
pass
def get_area(self):
pass
# To create a class that uses inheritance and polymorphism
# from another class:
class Rectangle(Shape):
def __init__(self, height, width): # The constructor
super.__init__()
self.height = height
self.width = width
def get_area(self):
return self.height * self.width