转载:Python 内建函数列表 > Python 的内置函数 slice

def slice(stop):
    '''
    生成 0 到 stop (不含 stop)的切片

    :param stop: 停止值
    :return: 切片
    '''

def slice(start, stop, step=1):
    '''
    生成 start 到 stop (不含 stop)的切片

    :param start: 起始值
    :param stop: 停止值
    :param step: 步长
    :return: 切片
    '''

示例:

运行示例

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(numbers[slice(3)])
print(numbers[slice(3, 10)])
print(numbers[slice(3, 10, 3)])

参考:

Python官方文档-slice