if statement - Python what does if 'self.root' do? -


for example:

def __init__(self):     self._root = none  def get(self, key):     if self._root:         return self._root.get(key).value     raise keyerror 

what if self._root: return? self._root not boolean.

well there many ways @ it. straight forward way check happen simple, check flow simple "if" statement.

>>> if none: ...     print("true") ... else: ...     print("false") ... false 

now, more indicative, can check non "none" value , see happens.

>>> = "asf" >>> if a: ...     print("true") ... else: ...     print("false") ... true >>> = none >>> if a: ...     print("true") ... else: ...     print("false") ... false 

so if statement got there checks if self._root none or not, , calls method of if it's not none.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -