python 字符串函数总结

简介:

1. isdigit()   判断字符串内容是否全部为数字。是True;否False。

2. s.isalpha()    测试s中所有的字符是否全是字母。

         

3. s.isalnum()    测试s中所有的私服是否全为数字或字母。eg:

          

4. s.istitle()   测试s中是否所有的词都是首字母大写。eg:

         

5. count()   判断字串中出现特定字串的次数。eg:

        s = '123 345 123 34'

        s.count('123')                        #结果是2

6.chr()    ascii码转变为字符。

7.ord()   字符转变为ascii码。eg:

        

8.upper()   把字串全部转换成大写

9.lower() 把字串全部转换为小写

11.capitalize() 把字串的首个字母变成大写

12.title() 把字串中的每个单词的首字母大写

8 9 10 11 eg:

        







本文转自jihite博客园博客,原文链接:http://www.cnblogs.com/kaituorensheng/archive/2012/09/25/2703226.html,如需转载请自行联系原作者

相关文章
|
5月前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
387 100
|
5月前
|
开发者 Python
Python中的f-string:高效字符串格式化的利器
Python中的f-string:高效字符串格式化的利器
540 99
|
5月前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
|
5月前
|
开发者 Python
Python f-strings:更优雅的字符串格式化技巧
Python f-strings:更优雅的字符串格式化技巧
|
5月前
|
开发者 Python
Python f-string:高效字符串格式化的艺术
Python f-string:高效字符串格式化的艺术
|
5月前
|
Python
使用Python f-strings实现更优雅的字符串格式化
使用Python f-strings实现更优雅的字符串格式化
|
6月前
|
索引 Python
python 字符串的所有基础知识
python 字符串的所有基础知识
403 0
|
6月前
|
Python
Python字符串center()方法详解 - 实现字符串居中对齐的完整指南
Python的`center()`方法用于将字符串居中,并通过指定宽度和填充字符美化输出格式,常用于文本对齐、标题及表格设计。
|
6月前
|
Python
Python中的f-string:更简洁的字符串格式化
Python中的f-string:更简洁的字符串格式化
366 92

推荐镜像

更多