新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonupper()
python 中的upper()函數(shù)有助于返回原始字符串的副本,其中字符串的所有小寫(xiě)字符都被轉(zhuǎn)換為大寫(xiě)。如果沒(méi)有小寫(xiě)字母,它將返回原始字符串。

**string.upper()**
上()參數(shù):
upper()方法不接受任何參數(shù)。在轉(zhuǎn)換時(shí),所有符號(hào)和字母都被忽略。
上()返回值
返回值始終是字符串。此方法類似于大寫(xiě)()方法,不同之處在于大寫(xiě)()僅將單詞的第一個(gè)字母轉(zhuǎn)換為大寫(xiě),而大寫(xiě)()將字符串的所有字符轉(zhuǎn)換為大寫(xiě)。
| 投入 | 返回值 | | 線 | 大寫(xiě)字符串 |
Python 中的upper()方法示例
示例 1:如何將字符串轉(zhuǎn)換為大寫(xiě)
# example string
string = "How are you?"
print(string.upper())
# string with numbers
string = "Hii! How Are You123?"
print(string.lower())
輸出:
HOW ARE YOU?
HII! HOW ARE YOU123?
示例upper()在程序中如何與條件檢查一起使用?
# first string
String1 = "ProgRammIng LanGuaGe!"
# second string
String2 = "programming language!"
if(String1.upper() == String2.upper()):
print("The two strings are same.")
else:
print("The two strings are not same.")
輸出:
The two strings are same. 本文題目:創(chuàng)新互聯(lián)Python教程:Pythonupper()
分享鏈接:http://fisionsoft.com.cn/article/djijppp.html


咨詢
建站咨詢
