代码:

import string

s
= ' The quick brown fox jumped over the lazy dog. '

print s
print string.capwords(s)

结果:

The quick brown fox jumped over the lazy dog.
The Quick Brown Fox Jumped Over The Lazy Dog
.
请按任意键继续
. . .

string模块中的capwords()函数,除了可以将每个单词首字母大写以外,它还能够去除两端的空格,再将连续的空格用一个空格代替。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2021-12-06
  • 2021-11-15
猜你喜欢
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
相关资源
相似解决方案