1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Python | 句中所有单词首字母大写

Python | 句中所有单词首字母大写

时间:2020-07-02 20:35:34

相关推荐

Python | 句中所有单词首字母大写

参考:geeokori

https://mp./s/bJiP5NwZ8fvDw0aPp49wbA

方法1:使用capitalize()

#输入英文句子s='''1999 cyberspace electronic security act2002 cyber security research and development act2002 networking and information technology research and advancement act.'''print(" ".join([word.capitalize() for word in s.split()]))#运行结果# 1999 Cyberspace Electronic Security Act# 2002 Cyber Security Research And Development Act# 2002 Networking And Information Technology Research And Advancement Act.

方法2:使用string中的capwords()模块

import strings=''' '''print(string.capwords(s)}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。