FINLAB

02

Oct 5th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. '''
  2. 1. 基本字串處理
  3. '''
  4. s = 'Hello' + 'Python' # str + str
  5. s
  6. s = 'Hello' * 3 + 'Python'
  7. s
  8. s[5:10] #from 5~9 (不包含10)
  9.  
  10. '''
  11. 2. 字串切割(Split)
  12. '''
  13. s = 'hello, world, I, am, Python'
  14. words = s.split(',') #回傳到串列,以()內的字元切割字串
  15. words
  16.  
  17. '''
  18. 3. 字串合併(Join)
  19. '''
  20. ",".join(words)  #用“”內的字元來串接
  21.  
  22. '''
  23. 4. 大小寫轉換
  24. '''
  25.  
  26. "HELLO".lower()
  27. 'hello'.upper()
  28. a ="hello"
  29. a
  30. a.upper()
Advertisement
Add Comment
Please, Sign In to add comment