write a program to access the class method. define a variable inside method and print its value after accessing it.
class my_class:
def __init__(self):
self.variable = None
def set_variable(self, x):
self.variable = x
def get_variable(self):
return self.variable
my_object = my_class()
my_object.set_variable("hello")
print(my_object.get_variable())
Integer Access
class my_class:
def __init__(self):
self.variable = None
def set_variable(self, x):
self.variable = x
def get_variable(self):
return self.variable
my_object = my_class()
my_object.set_variable(25)
print(my_object.get_variable())
0 Comments