Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 当列表长度小于return语句中使用的索引时,为什么不抛出索引器?_Python 3.x - Fatal编程技术网

Python 3.x 当列表长度小于return语句中使用的索引时,为什么不抛出索引器?

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个项目,它只返回全部

以下是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个项目,它只返回全部