python基礎程式設計_29_map()函式的大小寫轉換
阿新 • • 發佈:2019-02-14
>>> a='abcdefgh'
>>> a=list(a)
>>> a
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
>>> list(map(str.upper,a))
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
>>>
1. 對字串中所有字元(僅對字母有效)的大小寫轉換
>>>print ('just to test it'.upper()) #所有字母都轉換成大寫
>>>JUST TO TEST IT
>>>print ('JUST TO TEST IT'.lower() )#所有字母都轉換成小寫
>>>just to test it
2. 對字串中的字元(僅對字母有效)部分大小寫轉換:
>>>print ('JUST TO TEST IT'.capitalize()) #字串的首字母轉換成大寫, 其餘轉換成小寫
>>>Just to test it
>>>print ('JUST TO TEST IT'.title()) #字串中所有單詞的首字母轉換成大寫, 其餘轉換成小寫
>>>Just To Test It
3. 判斷字串大小寫函式:
>>>print ('JUST TO TEST IT'.isupper() )
>>>True
>>>print ('JUST TO TEST IT'.islower() )
>>>False
>>>print ('JUST TO TEST IT'.istitle() )
>>>False