001 012 Python 字串大小寫轉化

2021-06-20 21:19:08 字數 594 閱讀 2633

**如下:

#encoding=utf-8

print '中國'

#字串大小寫轉化

str ='abc中國'

ustr =u'abc中國'

print str.upper()

print str.lower()

print str.capitalize() #第乙個大寫其餘小寫

print ustr.upper()

print ustr.lower()

print ustr.capitalize()

#判斷是否是第乙個大寫其餘小寫 不適用於空字串和非字母字串

def iscapitalize(s):

return s == s.capitalize()

print iscapitalize(str)

print iscapitalize(ustr)

執行結果:

中國abc中國

abc中國

abc中國

abc中國

abc中國

abc中國

false

false

python字串 Python 字串

建立字串很簡單,只要為變數分配乙個值即可。例如 var1 hello world var2 python runoob python訪問字串中的值python不支援單字元型別,單字元在 python 中也是作為乙個字串使用。python訪問子字串,可以使用方括號來擷取字串,如下例項 例項 pytho...

python字串 python字串

單引號示例常用的轉義字元 轉義字元案例1format 格式化練習1 help sisdigit,isnumeric,isdecimal 三個判斷數字的函式 isalnum 檢查字串是否由字母加數字組成 s test1split 字串拆分 splitlines 已換行符拆分 join 合成字串 upp...

python字串用法 python字串使用總結

python 字串使用總結 字串是程式中最常見的資料型別。在 python 中,可以使用三種方式定義字串。單 引號 雙引號和三引號。例如 string string string 或者是 string 在使用上,單引號和雙引號沒有什麼區別。三引號的主要功能是在字串中可以 包含換行 也就是說,在三引號...