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

python String模塊在實(shí)際應(yīng)用的代碼介紹

開(kāi)發(fā) 后端
本文以python String模塊的相關(guān)代碼的方式來(lái)介紹python String模塊的具體應(yīng)用方法的介紹,那么下面的文章就讓我們一起分享吧!

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

推薦使用str類,而不是string模塊:String模塊提供了常用的字符串處理函數(shù);這些函數(shù)通??梢栽趕tr類中找到對(duì)應(yīng);python String模塊內(nèi)提供的某些常量還是非常有用的。

string成員常量:

  1. ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHI
    JKLMNOPQRSTUVWXYZ'
     
  2. ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' 
  3. ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
  4. letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij
    klmnopqrstuvwxyz'
     
  5. lowercase = 'abcdefghijklmnopqrstuvwxyz' 
  6. uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
  7. digits = '0123456789' 
  8. hexdigits = '0123456789abcdefABCDEF' 
  9. octdigits = '01234567' 
  10. whitespace = '\t\n\x0b\x0c\r ' 
  11. punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'  
  12. printable = '0123456789abcdefghijklmnopqrstuvwxyz
    ABCDEFGHIJKLMNOPQRSTU...  
     

 

 

成員函數(shù):

  1. atof(s) -> float  
  2. >>> atof = string.atof  
  3. >>> atof("3.14")  
  4. 3.1400000000000001  
  5. >>> atof("1")                  

 可以處理整數(shù)

  1. 1.0  
  2. >>> atof("-9")                

 

可以處理正負(fù)號(hào)不可以在數(shù)字字符尾端加‘f’

  1. Traceback (most recent call last):  
  2. File "<pyshell#24>", line 1, in <module> 
  3. atof("3.14f")  
  4. File "C:\Python26\lib\string.py", line 386, in atof  
  5. return _float(s)  
  6. ValueError: invalid literal for float(): 3.14f  
  7. >>> atof("s3.14")                

遇到錯(cuò)誤輸入,拋出異常

  1. Traceback (most recent call last):  
  2. File "<pyshell#26>", line 1, in <module> 
  3. atof("s3.14")  
  4. File "C:\Python26\lib\string.py", line 386, in atof  
  5. return _float(s)  
  6. ValueError: invalid literal for float(): s3.14  
  7. atoi(s [,base]) -> int  
  8.  

轉(zhuǎn)換字符串S為整數(shù),base默認(rèn)為10。以上的文章就是對(duì)python String模塊的相關(guān)介紹。

 【編輯推薦】

  1. python語(yǔ)法入門(mén)中導(dǎo)入import與from時(shí)的代碼示例
  2. Python 中文亂碼問(wèn)題的分析的具體方案介紹
  3. python 編程語(yǔ)言在操作文件編碼格式的應(yīng)用
  4. Python安裝配置的具體步驟的相關(guān)介紹
  5. Python 配置文件的實(shí)際應(yīng)用解析

 

責(zé)任編輯:佚名 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-04-09 16:26:53

Oracle join

2010-03-17 15:58:08

Python環(huán)境

2010-03-19 15:16:11

Python代碼

2010-04-27 09:28:55

綁定變量

2010-03-17 17:06:10

python腳本語(yǔ)言

2010-03-26 16:17:24

Python嵌入

2010-03-22 15:58:08

Python模塊功能

2010-04-23 11:15:43

Oracle創(chuàng)建

2010-03-19 12:49:20

Python編程

2009-12-02 19:51:54

PHP Switch語(yǔ)

2010-03-16 18:59:47

Python模塊

2010-04-09 18:15:47

Oracle 字符串

2010-03-23 18:20:26

Python os.g

2009-12-18 10:58:17

Linux應(yīng)用程序

2010-03-05 13:48:24

Python for

2010-03-17 09:32:16

Python安裝筆記

2010-03-25 18:37:28

Python技巧

2010-03-23 08:56:38

Python隨機(jī)數(shù)模塊

2010-03-22 19:11:55

Python連接

2009-12-14 18:09:32

路由選擇協(xié)議
點(diǎn)贊
收藏

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