[英]'in' and '==' in Python
What's the difference in the usage of in
and ==
in python ? python中
in
和==
的用法有什么区别? I want to explore more while comparing with a single character .我想在与单个字符比较的同时探索更多。
if gender in "M":
print "Male"
if gender == "M":
print "Male"
Of the following, which one can be more beneficial to use, in
or ==
?以下哪一个更有益于使用,
in
或==
?
in your case there is no need to use in, since you are comparing one character.在您的情况下,无需使用 in,因为您正在比较一个字符。
use ==使用==
当您使用“in”时,它表示列表中的一个对象(“money”表示 m、o、n、e、y 中的任何一个)但 == 表示整笔钱。
Use ==
:使用
==
:
>>> "" in "M"
True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.