Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- 1. 基本字串處理
- '''
- s = 'Hello' + 'Python' # str + str
- s
- s = 'Hello' * 3 + 'Python'
- s
- s[5:10] #from 5~9 (不包含10)
- '''
- 2. 字串切割(Split)
- '''
- s = 'hello, world, I, am, Python'
- words = s.split(',') #回傳到串列,以()內的字元切割字串
- words
- '''
- 3. 字串合併(Join)
- '''
- ",".join(words) #用“”內的字元來串接
- '''
- 4. 大小寫轉換
- '''
- "HELLO".lower()
- 'hello'.upper()
- a ="hello"
- a
- a.upper()
Advertisement
Add Comment
Please, Sign In to add comment