1. 程式人生 > 其它 >Python字串:交換大小寫 str.swapcase()

Python字串:交換大小寫 str.swapcase()

技術標籤:# 4.2 Pythonpython字串strswapcase

str.swapcase()

返回原字串的副本,其中大寫字元轉換為小寫,反之亦然。 請注意 s.swapcase().swapcase() == s 並不一定為真值。

# coding:utf-8

info_one = 'Python Code Is Good'
info_two = 'PYTHON DJANGO FLASK'
info_three = 'python web so easy'

info_one_new = info_one.swapcase()
info_two_new = info_two.
swapcase() info_three_new = info_three.swapcase() print(info_one_new) print(info_two_new) print(info_three_new)

在這裡插入圖片描述