Does this:
if key == "name" and item:
mean the same as this:
if key == "name" and if key == "item":
If so, I'm totally confused about example 5.14 in Dive Into Python. How can key be equal to both "name" and item? On the other hand, does "and item" simply ask whether or not item exists as a variable?
if key == "name" and item: means if (key == "name") and (item evaluates to True).
if (key == "name") and (item evaluates to True)
Keep in mind that (item evaluates to True) is possible in several ways. For example if (key == "name") and [] will evaluate to False.
(item evaluates to True)
if (key == "name") and []
False
1.4m articles
1.4m replys
5 comments
57.0k users