Python隨筆,day1,python隨筆day1

來源:互聯網
上載者:User

Python隨筆,day1,python隨筆day1

  1. #python中不存在單個字元的運算,只有字串函數  
  2. >>> s="www.google.com"  
  3. >>> s  
  4. 'www.google.com'  
  5. >>> s.split('.')                 #無參數全部切割  
  6. ['www', 'google', 'com']  
  7. >>> s.split('.',1)               #分隔一次  
  8. ['www', 'google.com']  
  9. >>> s.split('.')[1]              #取出被'.'分開的第一個字串  
  10. 'google'  
  11. >>> s.split('.',-1)              #小於0 的參數為全部切割  
  12. ['www', 'google', 'com']  
  13. >>> s1,s2,s3=s.split('.',2)      #s1,s2,s3分別賦值得到被切割的三個部分  
  14. >>> s1  
  15. 'www'  
  16. >>> s2  
  17. 'google'  
  18. >>> s3  
  19. 'com'  
  20. >>> s='''''call                    #切割分行符號! 
  21. me 
  22. baby'''  
  23. >>> s  
  24. 'call\nme\nbaby'  
  25. >>> print s                     #print顯示效果  
  26. call  
  27. me  
  28. baby  
  29. >>> s.split('\n')  
  30. ['call', 'me', 'baby']  
  31. >>> s="hello world!<[www.google.com]>byebye"  #經典範例  
  32. >>> s  
  33. 'hello world!<[www.google.com]>byebye'  
  34. >>> s.split('[')[1].split(']')[0]  
  35. 'www.google.com'  
  36. >>> s.split('[')[1].split(']')[0].split('.')  
  37. ['www', 'google', 'com']  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.