I am beginner in python. I cant understand simple thing with type None . When I assign None values to my parameters in constructor . I get error. What is the trick . Code with error:
class A(object):
def __init__(self):
self.root = None
def method_a(self, foo):
if self.root is None:
print self.root + ' ' + foo
a = A() # We do not pass any argument to the __init__ method
a.method_a('Sailor!') # We only pass a single argument
The error:
Traceback (most recent call last):
File "C:/Users/Dmitry/PycharmProjects/Algorithms/final_bst.py", line 11, in <module>
a.method_a('Sailor!') # We only pass a single argument
File "C:/Users/Dmitry/PycharmProjects/Algorithms/final_bst.py", line 7, in method_a
print self.root + ' ' + foo
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
As soon as I change None type in init for something like string variable it works correctly.