温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python中如何使用 String模块

发布时间:2021-07-05 17:10:38 来源:亿速云 阅读:140 作者:Leah 栏目:编程语言

本篇文章为大家展示了python中如何使用 String模块,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

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...   

成员函数:

atof(s) -> float  >>> atof = string.atof  >>> atof("3.14")  3.1400000000000001  >>> atof("1")

可以处理整数

  1. 1.0  

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


可以处理正负号不可以在数字字符尾端加&lsquo;f&rsquo;

Traceback (most recent call last):  File "<pyshell#24>", line 1, in <module> 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")

遇到错误输入,抛出异常

Traceback (most recent call last):  File "<pyshell#26>", line 1, in <module> 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

上述内容就是python中如何使用 String模块,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI