class Pagination:
def __init__(self, total_count, per_page_count, page_num):
"""
:param total_count: 数据总条数
:param per_page_count: 每页数据显示的条数
:param page_num: 当前查看的页数
"""
self.total_count = total_count
self.per_page_count = per_page_count
self.page_num = page_num
# 每页数据显示10条数据
# 第1页索引: 0:10
# 第2页索引: 11:20
# 第3页索引: 21:30
@property
def start(self):
return (self.page_num - 1) * self.per_page_count
@property
def end(self):
return self.page_num * self.per_page_count
data_list = [1, 2, 34, 4, 5, 56, 11, 1, 243, 1234]
pager = Pagination(192, 10, 3)
ret = data_list[pager.start:pager.end] # 属性方法调用时,就不需要加括号了
print(ret)