Team: I am new to python and doing my first implementation of class. probably am missing some learning from online tutorials. please help clarify why am I not able to print the variable that is attribute of a function def of a class. I want expected output. not sure what concept am missing. Please clarify. thanks. I don't know how to use return in my use case. Please clarify with working code.
code
class testClass:
def __init__(self):
classVar = "classString"
def Func1(self):
self.testVar1 = "string1"
print("in f1")
def Func2(self):
self.testVar2 = "string2"
print("in f2")
tco = testClass()
tco.Func1()
tco.Func2()
tcfo=tco.Func1()
print(tcfo.testVar1)
output
class-example.py
in f1
in f2
in f1
Traceback (most recent call last):
File "/python/class-example.py", line 20, in <module>
print(tcfo.testVar1)
AttributeError: 'NoneType' object has no attribute 'testVar1'
expected output
in f1
in f2
in f1
string1