新聞中心
python String模塊是一種應(yīng)用相當(dāng)廣泛,在實(shí)際操作中功能十分強(qiáng)大的計(jì)算機(jī)語言,但是懂得如何簡(jiǎn)捷的運(yùn)用python string模塊的這一語言的人卻不占大多數(shù),以下的內(nèi)容就是對(duì)python String模塊在實(shí)際運(yùn)用的解析。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),湖南企業(yè)網(wǎng)站建設(shè),湖南品牌網(wǎng)站建設(shè),網(wǎng)站定制,湖南網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,湖南網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
推薦使用str類,而不是string模塊:String模塊提供了常用的字符串處理函數(shù);這些函數(shù)通??梢栽趕tr類中找到對(duì)應(yīng);python String模塊內(nèi)提供的某些常量還是非常有用的。
string成員常量:
- ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHI
JKLMNOPQRSTUVWXYZ'- ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
- ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij
klmnopqrstuvwxyz'- lowercase = 'abcdefghijklmnopqrstuvwxyz'
- uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- digits = '0123456789'
- hexdigits = '0123456789abcdefABCDEF'
- octdigits = '01234567'
- whitespace = '\t\n\x0b\x0c\r '
- punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
- printable = '0123456789abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTU...
成員函數(shù):
- atof(s) -> float
- >>> atof = string.atof
- >>> atof("3.14")
- 3.1400000000000001
- >>> atof("1")
可以處理整數(shù)
- 1.0
- >>> atof("-9")
可以處理正負(fù)號(hào)不可以在數(shù)字字符尾端加‘f’
- Traceback (most recent call last):
- File "
", line 1, in - atof("3.14f")
- File "C:\Python26\lib\string.py", line 386, in atof
- return _float(s)
- ValueError: invalid literal for float(): 3.14f
- >>> atof("s3.14")
遇到錯(cuò)誤輸入,拋出異常
- Traceback (most recent call last):
- File "
", line 1, in - atof("s3.14")
- File "C:\Python26\lib\string.py", line 386, in atof
- return _float(s)
- ValueError: invalid literal for float(): s3.14
- atoi(s [,base]) -> int
轉(zhuǎn)換字符串S為整數(shù),base默認(rèn)為10。以上的文章就是對(duì)python String模塊的相關(guān)介紹。
本文題目:pythonString模塊在實(shí)際應(yīng)用的代碼介紹
分享鏈接:http://m.fisionsoft.com.cn/article/dpdcdsg.html


咨詢
建站咨詢
