Python“如果X == Y和Z”句法 [英] Python "if X == Y and Z" syntax

查看:186
本文介绍了Python“如果X == Y和Z”句法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是:

if key == "name" and item:

与此相同:

if key == "name" and if key == "item":

如果是,我是完全混淆了 Dive Into Python中的示例5.14 。键如何等于名称和项目?另一方面,和项目只是询问项目是否作为变量存在吗?

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和item:表示 if(key ==name)和(item计算结果为True)

请记住,(项目评估为True)可以通过多种方式实现。例如 if(key ==name)和[] 将评估为 False

Keep in mind that (item evaluates to True) is possible in several ways. For example if (key == "name") and [] will evaluate to False.

这篇关于Python“如果X == Y和Z”句法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆