Feb-16-2020, 05:55 AM
When you run this little program it prints out:
Inside the Simple constructor
constructor argument
constructor argument
A message: None
What i don't get is how "constructor argument" prints out twice in a row? I'm sure it has something to do with the comma in the showMsg(). Can anybody please explain:
1. why does it print out this way, i guess i am following the code wrong
2. what exactly that comma does?
3. does Python not print anything inside the showMsg() print statement until after the show() function has run a 2nd time?
Thank you for any help, i know this is probably very basic, just picking up coding again for the first time in 17 years....used C back then in college.
Inside the Simple constructor
constructor argument
constructor argument
A message: None
What i don't get is how "constructor argument" prints out twice in a row? I'm sure it has something to do with the comma in the showMsg(). Can anybody please explain:
1. why does it print out this way, i guess i am following the code wrong
2. what exactly that comma does?
3. does Python not print anything inside the showMsg() print statement until after the show() function has run a 2nd time?
Thank you for any help, i know this is probably very basic, just picking up coding again for the first time in 17 years....used C back then in college.
class Simple:
def __init__(self, str):
print("Inside the Simple constructor")
self.s = str
def show(self):
print(self.s)
def showMsg(self, msg):
print(msg + ':',
self.show()) # Calling another method
if __name__ == "__main__":
# Create an object:
x = Simple("constructor argument")
x.show()
x.showMsg("A message")
