mercredi 30 janvier 2019

What is the check "if var:" actually doing in the background in Python3?

I kind of know the difference between var == None and var is None, however my question is about the following condition check:

if var:
  action

Is the above equivalent to:

if not var == None:
  action

or is it equivalent to:

if var is not None:
  action

Or does it depend on what is the current type of the "var" variable, how it performs the check?

Or does it have a completely different mechanic in the background?

Coming from that as a follow up what would happen if the value of "var" is actually 0 and it's of type float or int and I use the if var: construct?

Any insights about the inner workings of Python3 are much appreciated. Thanks!

Aucun commentaire:

Enregistrer un commentaire