首页 > 编程语言 > 详细

python习题四

时间:2020-07-02 21:00:38      阅读:64      评论:0      收藏:0      [点我收藏+]

题目描述:

将一个语句中每个单词的首字母转成大写字母。

举例:

转换前: "How can mirrors be real if our eyes aren‘t real"

转换后: "How Can Mirrors Be Real If Our Eyes Aren‘t Real"

 

解法一:

1 def to_jaden_case(string):
2     str_list = string.split()
3     for i in range(len(str_list)):
4         str_list[i] = str_list[i].capitalize()
5     return  .join(str_list)

解法二:

1 def to_jaden_case(string):
2     print( .join(i.capitalize() for i in string.split()))

 

python习题四

原文:https://www.cnblogs.com/yukifun/p/13226824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!