菜单

Python 轻松分页思路

2019年5月17日 - Php

一:

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]

懵懂天真嫉妒爱幻想写作的姑娘

营造了人家喜剧

扶植了投机的打响

预留毕生的不满

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图