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

在 Python 中比较字符串

  1. str1 = "Canada"
  2. str2 = "Canada"
  3. print(str1 is str2) # True
  4. print(str1 == str2) # True
  5. string1 = ''.join(['Ca', 'na', 'da'])
  6. string2 = ''.join(['Can', 'ada'])
  7. print(string1 is string2) # False
  8. print(string1 == string2) # True

Output:

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

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