Python's “in” set operator

前端 未结 5 1136
刺人心
刺人心 2020-12-25 09:24

I\'m a little confused about the python in operator for sets.

If I have a set s and some instance b, is it true that b i

5条回答
  •  [愿得一人]
    2020-12-25 09:45

    Yes it can mean so, or it can be a simple iterator. For example: Example as iterator:

    a=set(['1','2','3'])
    for x in a:
     print ('This set contains the value ' + x)
    

    Similarly as a check:

    a=set('ILovePython')
    if 'I' in a:
     print ('There is an "I" in here')
    

    edited: edited to include sets rather than lists and strings

提交回复
热议问题