1.字符串的创建和驻留机制
a='python' b="python" c='''python''' print(a,id(a)) print(b,id(b)) print(c,id(c))
2.字符串的查找
'''字符串的查找操作''' s='hello,hello' print(s.index('lo')) print(s.find('lo')) print(s.rindex('lo')) print(s.rfind('lo')) #print(s.index('k')) #ValueError: substring not found #print(s.rindex('k')) #ValueError: substring not found print(s.find('k')) #-1 print(s.rfind('k')) #-1
3.字符串比较大小写
'''字符串中大小写转换的方法''' s = 'hello,python' a = s.upper() print(a, id(a)) print(s, id(s)) b = s.lower() print(b, id(b)) print(s, id(s)) print(b == s) print(b is s) c = 'hello,Python' print(c.swapcase()) print(c.capitalize()) print(c.title())