String Method1
字串型別有的方法
大小寫
hi = 'How are you?'
# 轉換成小寫
print(hi.lower())
# 轉換成大寫
print(hi.upper())
# 判斷是否為小寫
print(hi.islower())
# 判斷是否為大寫
print(hi.isupper())判斷字串是否為特定類型字串
判斷字串是否以特定形式結尾或開頭
Last updated
hi = 'How are you?'
# 轉換成小寫
print(hi.lower())
# 轉換成大寫
print(hi.upper())
# 判斷是否為小寫
print(hi.islower())
# 判斷是否為大寫
print(hi.isupper())Last updated
string = 'abcde'
# 只有字母且不為空,則為真
print(string.isalpha())
string = '123abc'
# 字串只有數字或字母且不為空,則為真
print(string.isalnum())
string = '0012345'
# 字串只有數字,且不為空,則為真
print(string.isdigit())
string = '\n'
# 字串只含有空格,定位空格,或是換行字元,且不為空,則為真
print(string.isspace())print('This is Jason\'s notebook.'.startswith('This'))
print('This is Jason\'s notebook.'.endswith('book.'))