Suppose Im creating a class named Bar
:
class Bar:
def __init__(self, foo):
self.foo = foo
Once I create an object of Bar
, How should I get the value of the foo
variable?
Should I just type this?
my_class = Bar("Hello")
print(my_class.foo)
Or should I create a method get_foo()
?
class Bar:
def __init__(self, foo):
self.foo = foo
def get_foo(self):
return self.foo
And then write
my_class = Bar("Hello")
print(my_class.get_foo())
First or second option?