python习题四
题目描述:
将一个语句中每个单词的首字母转成大写字母。
举例:
转换前: "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()))