Python字符处理一些小问题

1 字符小写转换为大写

(1) upper():将字符转换为大写

(2) swapcase():将字符转换取反 


2 将0-100的数中的偶数插入一个列表中

lst = []
for el in range(101):
    if el % 2 ==0:
        lst.append(el)
print(lst)


3 关于倒叙的一些问题

lst= [1,2,3,4,5,6]

方法一:

lst.reverse()

方法二:

lst = [i for i in reversed(lst)]

方法三:

lst  = sorted(lst,reversed = True)

方法四:

lst = lst[::-1]


4 敏感字屏蔽

content = input("请输入您的评论:")
li = ["苍老师", "东京热", "武藤兰", "波多野结衣"]
for filterWord in li:
    # replaceWord = "*" * len(filterWord)
    content = content.replace(filterWord, "*" * len(filterWord))

print(content)





猜你喜欢

转载自blog.csdn.net/qq_33567641/article/details/80929000