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:

Constructor cannot be applied to given types?

A subclass does not have to have any constructor with “the same number of parameters in the constructor as the superclass”, but it does have to call some of its superclass’ constructors from its own constructor. If the superclass has a no-arg constructor, it is called by default if an explicit call to a superclass constructor is … Read more

warning: control may reach end of non-void function

Your function returns a bool but there’s a potential code path (e.g. z.count is 0) where it may reach the end of the function and return nothing. Hence, the warning issued by the compiler. Add return false; (or return true; but false seems appropriate with your current logic) at the end of your function. As pointed out by others, your else part is also wrong. I’d rewrite it … Read more

Understanding slice notation

It’s pretty simple really: There is also the step value, which can be used with any of the above: The key point to remember is that the :stop value represents the first value that is not in the selected slice. So, the difference between stop and start is the number of elements selected (if step is 1, the default). The other feature is that start or stop may be a negative number, which … Read more