将以下字符每一个语句的第一个单词的首字母变成大写,“.”代表一句话结束
str1='python has a built-in method named capitalize() to convert the first
character of a string into uppercase and change the rest of the characters
into lowercase, and this method can be used on string data in various ways
without just capitalizing on the first characters. how you can apply
this method in python script in different ways are shown
in this article.'
Python将字符串每一个语句的第一个单词的首字母变成大写。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- SmallAntJ 2022-03-19 22:15关注
str1='python has a built-in method named capitalize() to convert the first \ character of a string into uppercase and change the rest of the characters \ into lowercase, and this method can be used on string data in various ways \ without just capitalizing on the first characters. how you can apply \ this method in python script in different ways are shown \ in this article.' import re sentences = re.split(r'([.?!][\'"]* *)', str1) #考虑句子以句号、问好、感叹号及引号结尾,同时考虑句尾空格 #print(sentences) print("".join(map(lambda s: s.capitalize(), sentences)))
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 vs2022无法联网
- ¥15 TCP的客户端和服务器的互联
- ¥15 VB.NET操作免驱摄像头
- ¥15 笔记本上移动热点开关状态查询
- ¥85 类鸟群Boids——仿真鸟群避障的相关问题
- ¥15 CFEDEM自带算例错误,如何解决?
- ¥15 有没有会使用flac3d软件的家人
- ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
- ¥15 docker实践项目
- ¥15 利用pthon计算薄膜结构的光导纳