input() error – NameError: name ‘…’ is not defined

TL;DR input function in Python 2.7, evaluates whatever your enter, as a Python expression. If you simply want to read strings, then use raw_input function in Python 2.7, which will not evaluate the read strings. If you are using Python 3.x, raw_input has been renamed to input. Quoting the Python 3.0 release notes, raw_input() was renamed to input(). That is, the new input() function reads a … Read more

NameError: name ‘self’ is not defined

Default argument values are evaluated at function define-time, but self is an argument only available at function call time. Thus arguments in the argument list cannot refer each other. It’s a common pattern to default an argument to None and add a test for that in code: