题解 | #牛牛的朋友#

牛牛的朋友

http://www.nowcoder.com/practice/11bcc9a775b14d9f9b855634b9434b70

# 创建列表 friends_list
friends_list = ['Niu Ke Le', 'Niumei', 'Niuneng', 'GOLO']

# 请写一个replace函数,第一个参数是列表friends_list,第二个参数是要替换的数字index,即在函数中将列表元素修改成成列表下标值。
def replace(list, index):
    list[index] = index

# 使用print函数直接打印修改前的列表
print(friends_list)

# 使用for循环遍历列表 friends_list,每次调用replace函数替换列表中相应下标的元素
for index in range(len(friends_list)):
    replace(friends_list, index)

# 使用print函数直接打印修改后的列表,查看是否替换成功
print(friends_list)
    
全部评论

相关推荐

双尔:你就写拥有ai开发经历,熟练运用提示词,优化ai,提高ai回答质量
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务