Python 3.x 当列表长度小于return语句中使用的索引时,为什么不抛出索引器?
以下是python代码:Python 3.x 当列表长度小于return语句中使用的索引时,为什么不抛出索引器?,python-3.x,Python 3.x,以下是python代码: #!/usr/bin/python3 def top_three_new(input_list): return sorted(input_list, reverse=True)[:100] print(top_three_new([2, 1])) [:100]并不意味着它将返回第100个元素 [:n]返回上一个项目中的n个项目。如果少于n个项目,它只返回全部
#!/usr/bin/python3
def top_three_new(input_list):
return sorted(input_list, reverse=True)[:100]
print(top_three_new([2, 1]))
[:100]并不意味着它将返回第100个元素
[:n]返回上一个项目中的n个项目。如果少于n个项目,它只返回全部