列表和字符串的方法返回一个新的对象;直接加入到原对象中

a = []
w = input()
for x in w:
    if '0' <= x <= '9': # 这样可以提取出数字
        a.append(x) # append函数并不需要返回一个新的列表,并不需要进行赋值操作
        continue
    else:
        w = w.replace(x,'') # string.replace()操作会返回一个新的字符串
    
print(w,a)

posted @ 2021-07-15 15:33  索匣  阅读(136)  评论(0编辑  收藏  举报