字符串内置方法练习

#1、upper() :将字符串转换成大写
# print("abcd".upper())

#2、find :找出,显示
print("abcd".find('cd')) #打印c所在位置的索引

#3、split:用逗号分割字符串:
print("a,b,c,d".split(',')) #打印:['a', 'b', 'c', 'd']

#4、replace :替换
string = "Python is good"
print(string.replace('Python', 'python')) ##打印:python is good

#5、len:获取字符串的长度:
str= 'jsdfhjdgjhfg'
print(len(str)) #打印:12

#6、startswith:判断开头字母
a = "this is the book"
print(a.startswith('this')) #打印True

#7、lower:将字符串转换成小写
print("ABcd".lower())

#8、strip():移除字符串头尾指定的字符(默认为空格或换行符)
# 或字符序列, \n 就是换行符
print("this is a book\n".strip()) #打印 :this is a book
posted @ 2021-03-25 16:37  乘风破浪的小落夜  阅读(61)  评论(0编辑  收藏  举报