


错误代码如下,如果能运行,纯属巧合
i = ['taibai','alexC','AbC','egon','Ritian','Wusir','aqe']
(1)移除空格
i = [name.replace(" ", "") for name in i] print(i)
(2)以A或a开头,以结尾
new_i = [] for name in i: if name.startswith('A') or name.startswith('a') and name.endswith('C'): new_i.append(name) print(new_i)
(3)加入新列表并循环打印
new_list = [] for name in new_i: new_list.append(name.upper()) # 转换为大写 for name in new_list: print(name)
代码如下:
w = ["残废人", "独眼龙", "瞎子", "聋子", "傻子"] comment = input("请输入评论内容:") for word in w: comment = comment.replace(word, "***") print("过滤后的评论内容为:{}".format(comment))
将评论添加到一个列表中
comment_list = [] comment_list.append(comment) print("所有评论内容为:{}".format(comment_list))