python - Python 标题的正确大写

标签 python

<分区>

我正在寻找一个库,通过假设它是一个标题来正确地将给定的字符串大写。我知道有 string.title(),但它把所有作品都大写,而不仅仅是应该大写的作品。有人知道任何图书馆吗?

标题中不应大写的单词示例:

  • 命题(来自、来自等)
  • 冠词(a、an、the)
  • 货车

最佳答案

Google 的术语是“titlecase”。 first hitthe titlecase package :

$ pip install titlecase
...
$ python
...
>>> from titlecase import titlecase
>>> titlecase('the spam and eggs')
'The Spam and Eggs'

关于python - Python 标题的正确大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7816347/

相关文章:

python - 多尺度 CNN 网络 Python Keras

python - 如何将字符串转换为其 Base-10 表示形式?

Python 类型错误 : 'str' object is not callable

python - 改进 Canny 边缘检测

python - 如何使用带原始文字化的字符串正则表达式作为正确的正则表达式

Python Pandas 从复杂字典中创建记录

python - 将 Argparse 与 Google Admin API 结合使用

Python 通过引用 DLL 传递用户定义的类

python - 如何总结列表的数量

python - 在 Python 中解析 JSON 时出现各种错误