第26025题 单选题
Python实现移动列表所有零到尾部,横线处应填入的代码是?

有一组数据 [20, 0, 7, 0, 31] 存放在 nums 中,希望将列表中的所有零移动到列表尾,现有如下代码,请选择横线处应填入的正确代码:

nums = [20, 0, 7, 0, 31]
i, j = 0, 0
while i < len(nums):
    if nums[i] != 0:
        nums[j] = nums[i]
        j += 1
    i += 1
nums[j:] = ________
print(nums)
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析