Saturday, July 4, 2020

"None" keyword


Its data doesn't represent any reasonable value - actually, it's not a value at all; hence, it mustn't take part in any expressions.

“None” is a keyword.

Let’s consider the below snippet & output.








This cause a runtime error, described by the above message.

There are only two kinds of circumstances when “None” can be safely used:
  • when you assign it to a variable (or return it as a function's result)
  • when you compare it with a variable to diagnose its internal state.
Like below.







If a function doesn't return a certain value using a return expression clause, it is assumed that it implicitly returns “None”.

Sometimes it may be the symptom of a subtle mistake inside the function.








Output is

No comments:

Post a Comment