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

在 Python 中检查字符串是大写、小写还是混合大小写

  1. words = ['The', 'quick', 'BROWN', 'Fox',
  2. 'jumped', 'OVER', 'the', 'Lazy', 'DOG']
  3. print([word for word in words if word.islower()])
  4. print([word for word in words if word.isupper()])
  5. print([word for word in words if not word.islower() and not word.isupper()])

Output:

  1. ['quick', 'jumped', 'the']
  2. ['BROWN', 'OVER', 'DOG']
  3. ['The', 'Fox', 'Lazy']