Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
字符串函数_创想鸟

字符串函数

字符串函数

python 字符串函数:

python 有一组可以在字符串上使用的内置方法。

所有字符串方法都会返回新值。他们不会改变原始字符串。

1.**capitalize(): **将字符串的第一个字符大写。

name = "pritha"print(name.capitalize()) 
pritha

2.casefold():将字符串转换为小写

name = "pritha"print(name.casefold()) 
pritha

3.center():返回居中的字符串

name = "pritha"print(name.center(10,"-")) 
--pritha--

4.count():返回指定值在字符串中出现的次数

name = "lakshmipritha"print(name.count('a')) 
2

5.encode():返回字符串的编码版本

name = "lakshmipritha"print(name.encode()) 
b'lakshmipritha'

6.endswith():如果字符串以指定值结尾则返回 true

name = "lakshmi pritha"print(name.endswith('pritha')) 
true

7.find():在字符串中搜索指定值并返回找到它的位置

name = "lakshmi pritha"print(name.find('pritha')) 
8

8.format():格式化字符串中的指定值

name = "hello, {}. welcome to {}."print(name.format("pritha", "python")) 
hello, pritha. welcome to python.

9.format_map():格式化字符串中的指定值

text = "my name is {name} and i am {age} years old."data = {"name": "pritha", "age":30 }print(text.format_map(data))
my name is pritha and i am 30 years old.

10.index():在字符串中搜索指定值并返回找到它的位置

name= "lakshmi pritha"position = name.index("pritha")print(position)
8

11.isalnum():如果字符串中的所有字符都是字母数字,则返回 true

12.isalpha():如果字符串中的所有字符都在字母表中,则返回 true

13.isacii():如果字符串中的所有字符都是 ascii 字符,则返回 true

14.isdecimal():如果字符串中的所有字符都是小数,则返回 true

15.isdigit():如果字符串中的所有字符都是数字,则返回 true

16.isidentifier():如果字符串是标识符,则返回 true

17.islower():如果字符串中的所有字符均为小写,则返回 true

18.isnumeric():如果字符串中的所有字符都是数字,则返回 true

19.isprintable():如果字符串中的所有字符均可打印,则返回 true

20.isspace():如果字符串中的所有字符都是空格,则返回 true

21.istitle():如果字符串遵循标题规则,则返回 true

22.isupper():如果字符串中的所有字符均为大写,则返回 true

name = "pritha"print(name.isalnum())print(name.isalpha())print(name.isascii())print(name.isdecimal())print(name.isdigit())print(name.isidentifier())print(name.islower())print(name.isnumeric())print(name.isprintable())print(name.isspace())print(name.istitle())print(name.isupper())
TrueTrueTrueFalseFalseTrueTrueFalseTrueFalseFalseFalse

以上就是字符串函数的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1354002.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
构建企业代理系统:核心组件设计与优化
上一篇 2025年12月13日 18:11:01
重构规则引擎 DSL
下一篇 2025年12月13日 18:11:12

相关推荐

发表回复

登录后才能评论
关注微信