I created a class whith a method that print out one of it's fields:
class Rule:
def __init__ (self,number, callout):
self.number=number
self.callout=callout
def shout(self):
print(self.callout)
I then create a list of these objects to iterate over, calling shout() for each of them:
Fizz = Rule(3,"Fizz")
Buzz = Rule(5,"Buzz")
Rules = [Fizz,Buzz]
#example 1
for x in range(0, 2):
Rules[x].shout()
#example 2
for item in Rules:
print (item.shout())
The output of example 1 is: Fizz Buzz as expected. But the output of example 2 is: Fizz None Buzz None
Why do they perform differently? Thank you in advance :)