字符串最常用的方法
1 strip
y = "
This is lazy\t\n
"
print(y.strip())
# Remove Whitespace: 'This is lazy'
2 lower upper
print("DrDre".lower())
# Lowercase: 'drdre'
print("attention".upper())
# Uppercase: 'ATTENTION'
3 startswith endswith
print("smartphone".startswith("smart"))
# Matches the string's prefix against the argument: True
print("smartphone".endswith("phone"))
# Matches the string's suffix against the argument: True
4 find replace
print("another".find("other"))
# Match index: 2
print("cheat".replace("ch", "m"))
# Replaces all occurrences of the first by the second argument: meat
5 join
print(','.join(["F", "B", "I"]))
# Glues together all elements in the list using the separator string: F,B,I
print(len("Rumpelstiltskin"))
# String length: 15
print("ear" in "earth")
# Contains: True
大家在看
AI安装教程
AI本地安装教程
微软AI大模型通识教程
微软AI大模型通识教程
AI大模型入门教程
AI大模型入门教程
Python入门教程
Python入门教程
Python进阶教程
Python进阶教程
Python小例子200道练习题
Python小例子200道练习题
Python练手项目
Python练手项目
Python从零在线练习题
Python从零到一60题