有没有办法从列表中获取前10个结果.可能是这样的:
list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
list.fetch(10)
?
有没有办法从列表中获取前10个结果.可能是这样的:
list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
list.fetch(10)
?
list[:10]
将使用切片给出此列表的前10个元素.
但是,请注意,最好在not中使用list
作为变量标识符,因为Python已经使用了list
:list()
To find out more about these type of operations you might find this tutorial on lists helpful and the link @DarenThomas provided Explain Python's slice notation - thanks Daren)