#### 判斷構成元素
isalpha() \#判斷字符串是否全部由字母構成,若是,返回true,否則返回false
\>>> "hello".isalpha()
True
\>>> "23hello".isalpha()
False
\>>>
#### 分割
S.split( ) #將字符串根據某個分割符進行分割大S代表變量名
\>>> a="hello,world,hi,python"
\>>> a.split(",") #根據逗號分割出每個字符串,可用于文本處理或表格處理中
\['hello', 'world', 'hi', 'python'\] \#分割出來的結果自動用逗號隔開,得到一個list列表的返回值
\>>> t1,t2,t3,t4=a.split(",")
\>>> print(t1,t2,t3,t4)
hello world hi python
#### 去掉字符串里的空格
S.strip()
\>>> a=" hello "
\>>> a
' hello ' #hello的兩頭有空格
\>>> a.strip()
'hello' #去掉空格
\>>> a.lstrip() \#去掉左邊的空格
'hello '
\>>> a.rstrip() \#去掉右邊的空格
' hello'
#### 大小寫字母的轉化
S.upper( ) \#轉換為大寫字母
\>>> a
' hello '
\>>> a.upper()
' HELLO '
S.lower( ) \#轉換為小寫字母
\>>> b="WORLD"
\>>> b.lower()
'world'
\>>>
\>>> a="hello world hi python" \#將所有單詞的首字母轉化為大寫,且轉換完之后進行判斷
\>>> a.title()
'Hello World Hi Python'
\>>> b=a.title()
\>>> b.istitle() \#istitle()用來判斷第一個字母是否為大寫,
True
\>>> a="HELLO"
\>>> a.istitle() \#istitle()用來判斷第一個字母是否為大寫,
False
\>>> b="World"
\>>> b.istitle()
True
\>>>
join連接字符串
\>>> t="hello@world@hi@python"
\>>> b=t.split("@") \#用@符號隔開t字符串
\>>> b
\['hello', 'world', 'hi', 'python'\]
\>>> c="+".join(b) \#將b中的字符串用+連接
\>>> print(c)
hello+world+hi+python
\>>> c=\["1","2","3","4"\] \#也可用數組元素表示
\>>> "+".join(c)
'1+2+3+4'
\>>>