[Python] 字符串操作
2021-02-01 03:16
标签:highlight 出现 bsp isa RoCE min 输出 转换 pre 字符串操作 以下字符串可以 变量.函数() 也可以 "字符串".函数() capitalize() 首字母大写,其余转换为小写 输出 count() count("str"),统计字符串出现的次数,跟列表的用法一样 输出 center() center(number,"str") 让内容显示在中间,使内容两侧填充字符串,默认是空格 输出 endswith() endswith("str"),判断字符串结尾是否包含 “str“,是则True 否则False 输出 find() find("str") 查找字符串并返回索引值,如果不存在则返回 -1 输出 format_map() 和format用法一样,字符格式化。只是格式不一样 输出 isalnum() str.isalnum() 检查字符串是否仅为字母、数字,或者为字母数字混合,是则返回 True,否则返回 False 输出 isalpha() str.alpha() 检查字符串是否为字母,是则返回True,否则返回False 输出 isdecimal() str.isdecimal() 检查字符串是否只为十六进制 输出 [Python] 字符串操作 标签:highlight 出现 bsp isa RoCE min 输出 转换 pre 原文地址:https://www.cnblogs.com/ITkeyan/p/12813056.html
print("test TEST".capitalize())
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe D:/Python/Day02/test.py
Test test
Process finished with exit code 0
print("test test".count("t"))
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe D:/Python/Day02/test.py
4
Process finished with exit code 0
print("test".center(50,"-"))
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe D:/Python/Day02/test.py
-----------------------test-----------------------
Process finished with exit code 0
print("i am shuaige".endswith("ge"))
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe D:/Python/Day02/test.py
True
Process finished with exit code 0
print("i am shuaige".find("am"))
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe D:/Python/Day02/test.py
2
Process finished with exit code 0
print("my name is {name} i am {age} years old".format_map({"name":"DaHua","age":10}))
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe D:/Python/Day02/test.py
my name is DaHua i am 10 years old
Process finished with exit code 0
print("test123".isalnum())
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe D:/Python/Day02/test.py
True
Process finished with exit code 0
print("abc".isalpha())
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe D:/Python/Day02/test.py
True
Process finished with exit code 0
print("000000".isdecimal())