2022年 11月 4日

python中in的用法

Ps:字符串情况下最小单位为元素,列表情况下最小单位为字符串,字典情况下最小单位为键值对

1.

  1. #for i in list:
  2. #for i in dic:
  3. #for i in str:
  4. #for i in range(10):
  5. #for i in ...
  6. #for i not in ...

2.

  1. #if i in str:
  2. #if i in list:
  3. #if i in dict:
  4. #if i in ...
  5. #if i not in ...

3.

  1. res1 = 'a' in 'abc'
  2. res2 = 'a' not in 'abc'
  3. print(res1)
  4. print(res2)