I've been learning about classes and how to do "object-oriented" programming in python. However, I am still having difficulties understanding some of the concepts behind classes and methods. I know that classes act as a template to create an "object", but what exactly does this template do? What is the "self" parameter that is used? For example, I am confused as to what the following code does that can't be done without classes:
class Money:
def __init__ (self, v =0):
self.value = v
def getValue (self):
return self.value
class Wallet:
def __init__ (self, b = 0):
self.balance = b
def addMoney (self, c):
self.balance += c.value
def getTotal(self):
return self.balance
c1 = Money(50)
c2 = Money(100)
c3 = Money(5)
c4 = Money(20)
p = Wallet()
p.addMoney(c1)
p.addMoney(c2)
p.addMoney(c3)
p.addMoney(c4)
print(p.getTotal())
Wouldn't this be as easily achieved with some simple raw_input() function(s) that asks for c1, c2, c3, c4, etc and a function that adds the money together and returns it? Wouldn't that be possibly a way of doing the same thing that this class does, but with less lines of code, and the lack of a need of writing 5 methods to simply add up some numbers.