美文网首页
04python字符串方法

04python字符串方法

作者: 秋葵2022 | 来源:发表于2018-05-23 16:09 被阅读1次
常用的几个:

isdigit
replace
find
count
strip
center
split
format
join

python字符串方法

s = 'Hello world!'

  1. s.capitalize() #将字符串的第一个字母变成大写,其他字母变小写。
    结果:Hello world!

2.print(s.casefold()) #变为小写
结果:hello world!

  1. print(s.center(50,'*'))
    结果:*******************Hello world!*******************

  2. print(s.count('o')) #几个字母O
    结果: 2

5.print(s.count('o',0,5)) #从 0 到 5 几个O
结果: 1

6.print(s.endswith('!')) # 是否是以!结尾
结果:True

7.print('a\tb') #\t tab # \t tab键

\t.png

8.print(s.find('o')) #只取了第一个
结果:4

  1. print(s.find('o',0,3))
    结果 -1

10.print(s.find('o',0,5))
结果:4

  1. format
s1 = "I am {0},like {1}"
print(s1.format("gudon","blue"))

结果:I am gudon,like blue

  1. format
s2 = "I am {name},like {color}"
print(s2.format(name = "sky",color = "green"))

结果:I am sky,like green

  1. 判断是否是整数


    isdecimal
isdigit
  1. 判断是否是一个可用变量名


    isidentifier
  2. 是否是小写


    islower

16.是否都是大写


isupper

17.是否全部为数字


isnumeric

18.join


join

19.ljust、rjust


ljust.png
rjust.png

20.大小写 lower upper


lower and upper.png

21.去除多余空格等


strip
  1. partition


    partition
  2. replace


    replace.png

24.split


split
  1. rsplit


    rsplit
  2. startswith 以什么开头


    startswith

相关文章

  • 04python字符串方法

    常用的几个: isdigitreplacefindcountstripcentersplitformatjoin ...

  • JAVA之UUID去掉横线

    方法一(字符串截取) 方法一 方法二(字符串分割) 方法二

  • 字符串格式化,字符串方法

    字符串格式化 方法一 方法二 字符串方法

  • spring工具类最佳实践

    字符串处理函数 StringUtils方法分为三大类: 普通方法 格式化方法 字符串数组方法 常规方法 判定字符串...

  • 8章 对象方法

    本章大纲 字符串的方法 列表的方法 查看python手册 对象方法概念 字符串的方法 count 计算字符串中包含...

  • String 常用方法汇总

    截取字符串 字符串替换 字符串拼接 Stringbuilder 方法 StringJoiner 方法 setEmp...

  • String 字符串常用操作

    indexof()方法 substring() 方法substring() 方法返回字符串的子字符串 replac...

  • 针对ES6的新知识学习

    字符串startsWith()方法 判断字符串string是否是以str开头 字符串endsWith()方法 判断...

  • python字符串

    字符串常用方法 1、首字母大写 capitalize方法 2、字符串替换 replace方法 参数1:老字符串 参...

  • 字符串`trim()`方法的使用

    字符串trim()方法 trim()方法并不影响字符串本身,它返回的是一个新的字符串 trim()方法去除字符串两...

网友评论

      本文标题:04python字符串方法

      本文链接:https://www.haomeiwen.com/subject/fddtjftx.html