• slider image 221
:::

1-2 字串

字串

  • 字串: 單行文字,使用雙引號、單引號都相同。多行文字使用 3 個引號框住。
"teacher"   
'teacher'
"""多行文字
第二行
第三行"""
'5'+'3'  輸出結果為字串 53

字串運算

  • 'abc' + '123'
s1='abc' 
s1*2 
s1='0123456789'
s1[0]  --> 0
s1[-1] --> 9
s1[2:-2] --> 234567
s1[::-1] 反轉文字  [開始:結束:間隔]

 

  • s.split(',')
  • ','.join(list1)
  • s.find('abc') s.rfind('abc')
  • s.count('字') 字串出現的次數
  • s.strip(chars) 清除左右的空白或指定字元 rstrip lstrip

 

seafood = '師傅'
print('感恩{},讚嘆{}'.format(seafood,seafood))
print('感恩%s,讚嘆%s'%(seafood,seafood))

Google網站翻譯工具列

站內搜尋