将以下字符每一个语句的第一个单词的首字母变成大写,“.”代表一句话结束
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 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
- ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
- ¥15 关于#java#的问题,请各位专家解答!
- ¥15 如何卸载arcgis 10.1 data reviewer for desktop
- ¥15 共享文件夹会话中为什么会有WORKGROUP
- ¥15 关于#python#的问题:使用ATL02数据解算光子脚点的坐标(操作系统-windows)
- ¥115 关于#python#的问题:未加密前两个软件都可以打开,加密后只有A软件可打开,B软件可以打开但读取不了数据
- ¥15 在matlab中Application Compiler后的软件无法打开
- ¥15 想问一下STM32创建工程模板时遇到得问题
- ¥15 Fiddler抓包443