当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

Python中的字符串比较 is vs ==

  1. x = 'canada'
  2. y = ''.join(['ca', 'na', 'da'])
  3. print(x == y)
  4. print(x is y)
  5. x = [1, 2, 3]
  6. y = [1, 2, 3]
  7. print(x == y)
  8. print(x is y)
  9. z = y
  10. print(z is y)

Output:

  1. True
  2. False
  3. True
  4. False
  5. True

该分类下的相关小册推荐: