新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python字符串在實際中的操作手冊
Python字符串在使用的時候是需要我們進行詳細的學習。下面我們就看看在具體的操作中如何才能更好的進行這個字符串的使用方法。在之后的使用中還是需要我們繼續(xù)學習。

昭化ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
- #coding:utf-8
- #兩個小函數(shù)
- #一、查找字符在字符串中第一次出現(xiàn)的位置.
- def find(string, char):
- index = 0
- while index < len(string):
- if (string[index] == char):
- return index
- index += 11
- return -111
- #二、查找字符在字符串中的總數(shù)
- def findSum(string, char):
- index = 0
- count = 0
- while index < len(string):
- if (string[index] == char):
- count += 1
- index += 1
- return count
- #使用以上兩個函數(shù)
- print "字符1在字符串1211211234中第一次出現(xiàn)的位置: ", find("1211
211234", "1")- print "字符1在字符串1211211234中出現(xiàn)的次數(shù):", findSum("1211211
234", "1")- import string #引入string庫
- print string.find('www.cctv.com', 'com') #result=9
- print string.find('Good','d') #result = 3
- print string.find('canada', 'a',2,9) #result =3,用法如下:
- #string.find(s, sub[, start[, end]])函數(shù)說明
- #Return the lowest index in s where the substring sub is
found such that sub is- #wholly contained in s[start:end]. Return -1 on failure.
Defaults for start and- #end and interpretation of negative values is the same
as for slices.- print string.lowercase #常量,abcdefghijklmnopqrstuvwxyz
- print string.uppercase #常量,ABCDEFGHIJKLMNOPQRSTUVWXYZ
- print string.digits #常量,012345678937
- def isLower(char): #判斷一個字符是否為小寫
- if (string.find(string.lowercase, char) > -1):
- return 'Good'
- return 'bad'
- print isLower('S')
- def isLowertest(char): #另外一種判斷字符是否為小寫的方法
- return char in string.lowercase46 print isLowertest('a')
以上就是對Python字符串的相關介紹,希望大家有所收獲。
網(wǎng)頁名稱:Python字符串在實際中的操作手冊
網(wǎng)站路徑:http://www.dlmjj.cn/article/dhipjcd.html


咨詢
建站咨詢
