Python定义函数修改列表中元素,并返回显示

原列表:username=['Larry','Marry','Smith']

新列表:new_names=['the Great Smith','the Great Marry','the Great Larry']

def make_great(names):
    while names:
        current_name='the Great '+names.pop()
        new_names.append(current_name)
    return new_names

def show_magicians(names):
    for name in names:
        print(name)
        
new_names=[]
username=['Larry','Marry','Smith']
new_names=make_great(username)
show_magicians(new_names)
发布了5 篇原创文章 · 获赞 10 · 访问量 487

猜你喜欢

转载自blog.csdn.net/snail9610/article/details/97523058