移除字符串中的指定位置字符
"""移除字符串中的指定位置字符"""
test_str = "Runoob"
print("原始字符串:", test_str)
n = 3
str_new = test_str[:n - 1] + test_str[n:]
print("字符移除后:", str_new)
new_str = ""
for i in range(0, len(test_str)):
if i != n - 1:
new_str = new_str + test_str[i]
print("字符移除后:", new_str)
判断字符串是否存在子字符串
"""判断字符串是否存在子字符串"""
def check1(string, sub_str):
if string.find(sub_str) == -1:
print("不存在")
else:
print(("存在"))
def check2(string, sub_str):
if (sub_str in string):
print("存在")
else:
print("不存在")
string = "www.runoob.com"
sub_str = "runoob"
check1(string, sub_str)
check2(string, sub_str)