Python for the loop members in the operator in

in return for the loop element is a set of
members in the operator returns the result of the logical value of True / False

fish_record='鲫鱼5条、鲤鱼8条、鲢鱼7条、草鱼2条、黑鱼6条、乌龟1只'
if '乌龟' in fish_record:  #成员运算符
    print('乌龟在字符串')
else:
    print('乌龟不在字符串里')
    
if 15 not in range(10):   #成员运算符
    print('15不在集合里')
else:
    print('15在集合里')

operation result
Here Insert Picture Description

Published 13 original articles · won praise 0 · Views 2610

Guess you like

Origin blog.csdn.net/Heiraten/article/details/104398945