官方文档:https://docs.python.org/zh-cn/3/library/stdtypes.html#string-methods
- str.lower() :转换为小写
- str.islower() : 字符串里所有的字母是否为小写
- len(str) : 返回字符串的长度
- str1.count(str2) : str1中含有str2的数量
更多方法请参考官方文档
str = "Hello world"
print(str.islower())
print(str.lower())
print(str.count("o"))
print(str.find("w"))
#打印结果
#False
#hello world
#2
#6
本文深入讲解了Python中字符串的各种实用方法,包括转换为小写、检查所有字母是否为小写、计算子串出现次数及查找指定字符位置。通过具体代码示例,帮助读者更好地理解和运用这些方法。


被折叠的 条评论
为什么被折叠?



