Python 字符串大小寫轉(zhuǎn)換的簡(jiǎn)單實(shí)例
①所有字母都轉(zhuǎn)換為大寫
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'hello, world!'
print(a.upper())輸出:
HELLO, WORLD!
②所有字母都轉(zhuǎn)換為小寫
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'HELLO, WORLD!'
print(a.lower())輸出:
hello, world!
③首字母轉(zhuǎn)換成大寫, 其余轉(zhuǎn)換成小寫
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'HELLO, WORLD!'
print(a.capitalize())輸出:
Hello, world!
④所有單詞的首字母轉(zhuǎn)換成大寫, 其余轉(zhuǎn)換成小寫
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'HELLO, WORLD!'
print(a.title())輸出:
Hello, World!
⑤判斷所有字母都為大寫
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'HELLO, WORLD!'
print(a.isupper())
b = 'hello, world!'
print(b.isupper())輸出:
True
False
⑥判斷所有字母都為小寫
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'HELLO, WORLD!'
print(a.islower())
b = 'hello, world!'
print(b.islower())輸出:
False
True
⑦判斷所有單詞的首字母為大寫
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'HELLO, WORLD!'
print(a.istitle())
b = 'hello, world!'
print(b.istitle())
c = 'Hello, World!'
print(c.istitle())輸出:
False
False
True
以上這篇Python 字符串大小寫轉(zhuǎn)換的簡(jiǎn)單實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python3自動(dòng)生成MySQL數(shù)據(jù)字典的markdown文本的實(shí)現(xiàn)
這篇文章主要介紹了Python3自動(dòng)生成MySQL數(shù)據(jù)字典的markdown文本的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
python實(shí)現(xiàn)超市進(jìn)銷存管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)超市進(jìn)銷存管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
關(guān)于Python正則表達(dá)式模塊之re模塊
這篇文章主要介紹了關(guān)于Python正則表達(dá)式模塊之re模塊,?re模塊是Python中的重要組成部分,這里涉及到字符串的匹配,轉(zhuǎn)換,自定義格式化等,需要的朋友可以參考下2023-04-04
Tensorflow 訓(xùn)練自己的數(shù)據(jù)集將數(shù)據(jù)直接導(dǎo)入到內(nèi)存
這篇文章主要介紹了Tensorflow 訓(xùn)練自己的數(shù)據(jù)集將數(shù)據(jù)直接導(dǎo)入到內(nèi)存,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06
python中字符串變二維數(shù)組的實(shí)例講解
下面小編就為大家分享一篇python中字符串變二維數(shù)組的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-04-04
python 快速把超大txt文件轉(zhuǎn)存為csv的實(shí)例
今天小編就為大家分享一篇python 快速把超大txt文件轉(zhuǎn)存為csv的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-10-10
Appium Python自動(dòng)化測(cè)試之環(huán)境搭建的步驟
這篇文章主要介紹了Appium Python自動(dòng)化測(cè)試之環(huán)境搭建的步驟,以32位的Windows 7操作系統(tǒng)為例介紹Appium+Python的環(huán)境搭建步驟,感興趣的小伙伴們可以參考一下2019-01-01

