string = "hellow world"result = helloprint(string[0:5])
string = "hellow world"if "e" in string :
print("字母存在")
string = "hellow world"result = "hellow world"print(string.upper())
string = "hellow world"result = "hellow world"print(string.lower())
string = "hellow world"result = falseprint(string.islower())
string = "hellow world"result = falseprint(string.isupper())
isalpha():判斷字串全是字母,返回trueisalnum():判斷字串是字母或者數字,返回true
isdecima():判斷字串全是數字,返回true
isspace():判斷字串全是space, 返回true
istitle():判斷只有首字母大寫,返回true
list = ["red","blank","blue"]result = red,blank,bluecolor = ",".join(list)
print(color)
list = ["red","blank","blue"]result = ['red', 'blank', 'blue']color = ",".join(list)
content = color.split(",")
print(content)
rjust(10)右邊對齊,不足是個的用空格填充
python基礎 字串
轉義符 n換行 print 我是 nzzz 我是 zzz t製表符 print 我是 tzzz 我是 zzz 雙引號 print 我是 zzz 我是 zzz 單引號 print 我是 zzz 我是 zzz 續航符 name s z print name sz原始字串 原始字串 r abc r abc...
Python基礎字串
str1 hello python str1 str1.capitalize 把開頭轉換成大寫 print str1 str1 str1.center 8,居中並填充 print str1 str1 str1.find j 0,len str1 尋找元素所在的位置,沒在返回 1 print str1...
Python基礎 字串
判斷全部否是字母 str helloween if str.isalpha print 字母 判斷全部否是數字 str 1234 if str.isdecimal print 數字 判斷都是大寫 str abc if str.isupper print 大寫 判斷都是小寫 str abc if st...