What's the difference in the usage of in
and ==
in python ? 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 your case there is no need to use in, since you are comparing one character.
use ==
当您使用“in”时,它表示列表中的一个对象(“money”表示 m、o、n、e、y 中的任何一个)但 == 表示整笔钱。
Use ==
:
>>> "" in "M"
True
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.