任務:請設計一個函數,它接受一個字符串,然后返回一個僅首字母變成大寫的字符串。
參考答案應該修改一下吧?
想一下下面的情況:
1、傳入的參數全部是大寫字母,如:HELLO
2、傳入的參數是大寫字母開頭緊接小寫字母,如:Hello
3、傳入的參數是小寫字母開頭緊接大寫字母,如:hELLO
參考代碼如下:
def?firstCharUpper(s): ????return?s[0].upper()+s[1:].lower() print?firstCharUpper('hello') print?firstCharUpper('sunday') print?firstCharUpper('sHELL')
歡迎大家提出疑問。這只是一些小小的改正。
2016-08-26
def FirstChrCaptial(x):
? ? return x[0].upper()+x[1:].lower()
print FirstChrCaptial('hello')
print FirstChrCaptial('sunday')
print FirstChrCaptial('sHELL')
2016-10-08
def firstCharUpper(s):
#return (s[:1].upper()+s[1:])
return s.title()
print (firstCharUpper('hello'))
print (firstCharUpper('sunday'))
print (firstCharUpper('september'))
其中str.title()是python中的對于字符串首字母大寫的方法
2016-09-08
upper()和lower()就是Python為string對象提供的轉換大小寫的方法。
2016-09-07
可以介紹一下upper()和lower()的用法么?括號里面可以填參數嗎?
2016-08-26
def firstCharUpper(s):
? ? return s[:1].upper()+s[1:]