12、Pythonにおける文字列の大文字と小文字の変換

2255 ワード

Pythonの文字列の大文字と小文字の変換を簡単にまとめると、最後にリストを処理する方法が少し面白いです.
a = 'hello python'   #    
b = 'Hello python'   #       
c = 'Hello Python'   #            
d = 'HELLO PYTHON'   #        
f = 'hello,python'   #     
e = ['HELLO','python'] #  

print(a.capitalize())  #     
print(d.lower())       #    
print(a.upper())       #    
print(a.title())       #           
print(b.swapcase())    #     
print(f.title())       #     ,                
x = [item.lower() for item in e]  #             
print(x)

実行結果:
C:\Python36\python.exe E:/python/test1/linshi/8.py Hello python hello python HELLO PYTHON Hello Python hELLO PYTHON Hello,Python ['hello', 'python'] Process finished with exit code 0