自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python字符串在實際中的操作手冊

開發(fā) 后端
Python字符串如何進行相關(guān)環(huán)境的融合與使用。這個問題需要大家進行學(xué)習(xí)相關(guān)的知識。下面我們就詳細的看看相關(guān)的技術(shù)問題。

Python字符串在使用的時候是需要我們進行詳細的學(xué)習(xí)。下面我們就看看在具體的操作中如何才能更好的進行這個字符串的使用方法。在之后的使用中還是需要我們繼續(xù)學(xué)習(xí)。

  1. #coding:utf-8   
  2. #兩個小函數(shù)  
  3. #一、查找字符在字符串中第一次出現(xiàn)的位置.   
  4. def find(string, char):   
  5. index = 0   
  6. while index < len(string):   
  7. if (string[index] == char):   
  8. return index   
  9. index += 11  
  10. return -111   
  11. #二、查找字符在字符串中的總數(shù)  
  12. def findSum(string, char):  
  13. index = 0 
  14. count = 0 
  15. while index < len(string):  
  16. if (string[index] == char):  
  17. count += 1  
  18. index += 1  
  19. return count  
  20. #使用以上兩個函數(shù)  
  21. print "字符1在字符串1211211234中第一次出現(xiàn)的位置: ", find("1211
    211234", "1")  
  22. print "字符1在字符串1211211234中出現(xiàn)的次數(shù):", findSum("1211211
    234", "1")  
  23. import string #引入string庫  
  24. print string.find('www.cctv.com', 'com') #result=9 
  25.  print string.find('Good','d') #result = 3 
  26. print string.find('canada', 'a',2,9) #result =3,用法如下:  
  27. #string.find(s, sub[, start[, end]])函數(shù)說明  
  28. #Return the lowest index in s where the substring sub is 
    found such that sub is  
  29. #wholly contained in s[start:end]. Return -1 on failure. 
    Defaults for start and  
  30. #end and interpretation of negative values is the same 
    as for slices.  
  31. print string.lowercase #常量,abcdefghijklmnopqrstuvwxyz  
  32. print string.uppercase #常量,ABCDEFGHIJKLMNOPQRSTUVWXYZ  
  33. print string.digits #常量,012345678937   
  34. def isLower(char): #判斷一個字符是否為小寫  
  35. if (string.find(string.lowercase, char) > -1):  
  36. return 'Good'  
  37. return 'bad'  
  38. print isLower('S')  
  39. def isLowertest(char): #另外一種判斷字符是否為小寫的方法  
  40. return char in string.lowercase46 print isLowertest('a')  

以上就是對Python字符串的相關(guān)介紹,希望大家有所收獲。

【編輯推薦】

  1. 探究Python性能為什么如此的強大
  2. Python編程語言在未來的發(fā)展趨勢
  3. Python多線程具體運用的方法
  4. Python編程語言的發(fā)展歷程介紹
  5. Python編程語言與Zpoe之間不解的情緣
責(zé)任編輯:張浩 來源: 博客園
相關(guān)推薦

2010-03-18 17:23:55

Java Socket

2010-03-11 18:21:43

Stackless P

2009-12-01 14:43:28

安裝RDAC驅(qū)動

2009-12-22 17:24:14

Linux配置Dual

2010-03-16 10:58:35

Python字符串

2009-12-23 16:29:01

Linux操作系統(tǒng)

2009-12-17 16:10:24

Linux系統(tǒng)安裝聲卡

2009-12-02 15:57:26

Linux系統(tǒng)

2010-03-16 16:22:36

Python字符串

2010-06-01 17:45:45

SVN 基本操作

2010-06-17 16:22:04

SQL Server

2010-03-22 18:53:53

Python格式化字符

2010-03-22 18:20:47

Python正則表達式

2010-06-07 16:36:29

MySQL連接字符串

2010-04-15 16:47:46

Oracle字段

2020-09-24 10:45:52

計算機互聯(lián)網(wǎng) 技術(shù)

2023-09-26 19:45:47

2010-06-17 16:38:14

MS SQL Serv

2010-09-06 17:30:46

SQL函數(shù)

2021-09-10 08:18:31

Go語言字符串
點贊
收藏

51CTO技術(shù)棧公眾號