I'm a bit new to the concept of OOP, but slightly I'm getting there. I do however have a question.
Suppose we have a class called Helloworld where you can input a string that is supposed to read a message to the world. The string is displayed with a function displaystring inside the class Helloworld. Nothing to fancy.
However, when I define an object msg1 containing the message I want to send to the world I'm unable to display it with displaystring without explicitly putting the message in the functioncall. Why is this? I already assigned my message to msg1 through Helloworld(message). By calling msg1.displaystring one would assume it would display the message which object msg1 contains. What am I doing wrong here?
- Code: Select all
#! /usr/bin/env python3.4
self.string = string
message = "Hi there folks!"
msg1 = Helloworld(message)
<bound method Helloworld.displaystring of <__main__.Helloworld object at 0x7fba059cb860>>
Hi there folks!
Added note: By using msg1.displaystring(message) you're actually calling for print(Helloworld(message).displaystring(message)). I find it strange I'd have to insert the message I want to display twice.