Python 简单分页思路
2023-09-27 14:26:02 时间
一:
li = []
for i in range(1000):
li.append(i)
while True:
p = input('input page: ')
p = int(p)
start = (p-1) * 10
end = p * 10
print(li[start:end])
运行结果:
input page: 1
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
input page: 2
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
input page: 5
[40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
input page:
二:
class Pagegenerate:
def __init__(self, current_page):
try:
p = int(current_page)
except Exception as e:
p = 1
self.page = int(current_page)
@property
def start(self):
val = (self.page-1) * 10
return val
@property
def end(self):
val = self.page * 10
return val
li = []
for i in range(1000):
li.append(i)
while True:
p = input("Enter the page to view: ")
obj = Pagegenerate(p)
print(li[obj.start:obj.end])
运行结果:
Enter the page to view: 2
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
Enter the page to view: 5
[40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
相关文章
- 【华为OD机试真题 python】查找重复代码【2022 Q4 | 100分】
- python中线程池的使用
- 2年python编程自学经历(已工作),分享一些真实的学习心得和避坑经验
- PythonPython数据分析有什么提高效率的方法?Python数据分析技巧有哪些
- 想转行学python过来人提醒大家几点
- python提供的多线程httpserver
- python pymysql安装
- Python爬虫技术--基础篇--面向对象编程(下)
- 时间差,时间戳和时间格式化python
- python 中numpy中函数hstack用法和作用
- Python 教程之在 Python中创建桑基图 Sankey Diagram
- linux系统 python虚拟环境安装TensorFlow
- 【Jenkins自动化部署】Linux节点的Python服务自动化构建
- 【华为OD机试真题 java、python、c++】机房布局(100%通过+复盘思路)
- 【华为OD机试真题 java、python、c++】静态扫描(100%通过+复盘思路)
- 华为OD机试 - 篮球比赛(Python) | 机试题+算法思路+考点+代码解析 【2023】
- 华为OD机试 -查找单入口空闲区域(Python) | 机试题+算法思路+考点+代码解析 【2023】
- 华为OD机试 - 吃火锅(Python) | 机试题+算法思路+考点+代码解析 【2023】
- 华为OD机试 - 判断牌型(Python) | 机试题+算法思路+考点+代码解析 【2023】
- 华为OD机试 - 猴子爬山(Python)| 真题+思路+考点+代码+岗位
- 华为OD机试 - 众数和中位数(Python)| 真题+思路+考点+代码+岗位
- python第十七课——列表生成式