1.将字符串 “abcd” 转成大写
2.计算字符串 “cd” 在 字符串 "abcd"中出现的位置
3.字符串 “a,b,c,d” ,请用逗号分割字符串,分割后的结果是什么类型的?
4."{name}喜欢{fruit}".format(name=“李雷”) 执行会出错,请修改代码让其正确执行
5.string = “Python is good”, 请将字符串里的Python替换成 python,并输出替换后的结果
6.有一个字符串 string = “python修炼第一期.html”,请写程序从这个字符串里获得.html前面的部分,要用尽可能多的方式来做这个事情
7.如何获取字符串的长度?
8.“this is a book”,请将字符串里的book替换成apple
9.“this is a book”, 请用程序判断该字符串是否以this开头
10.“this is a book”, 请用程序判断该字符串是否以apple结尾
11.“This IS a book”, 请将字符串里的大写字符转成小写字符
12.“This IS a book”, 请将字符串里的小写字符,转成大写字符
13.“this is a book\n”, 字符串的末尾有一个回车符,请将其删除
a = "abcd"
print(a.upper())
ABCD
"abcd".find("cd")
2
"a,b,c,d".split(",")
['a', 'b', 'c', 'd']
"a.b.c.d".split(".")
['a', 'b', 'c', 'd']
"{name}喜欢{fruit}".format(name="李雷",fruit="芒果")
'李雷喜欢芒果'
string = "Python is good"
string.replace("Python","python")
'python is good'
string = "python修炼第一期.html"
print(string[:11])
print(string[0:11])
print(string[-16:-5])
print(string.split(".")[0])
python修炼第一期
python修炼第一期
python修炼第一期
python修炼第一期
string = "bianxia"
print(len(string))
7
string = 'this is a book'
string.replace("book","apple")
'this is a apple'
string = "this is a book"
string.startswith("this")
True
string = "this is a book"
string.endswith("apple")
False
string = "This IS a book"
string.lower()
'this is a book'
string = "This IS a book"
string.upper()
'THIS IS A BOOK'
string = "this is a book\n"
string.strip()
'this is a book'
第二题可以直接使用find
第13小题,strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列, \n 就是换行符
参考了python基础130道练习题