zoukankan      html  css  js  c++  java
  • 面向对象成员实现分页

    class Pages:
    
        def __init__(self,nn):
            self.nn = nn          #获取输入的
    
        def start(self):
            s = (self.nn-1)*10+1  #分页开始
    
            return s
    
        def end(self):
            e = self.nn * 10 +1  #分页结束
            return e
    
    listfen=[]
    for li in range(100):
        listfen.append(li)  #添加数据到listfen中
    
    while True:
        p = input("请输入分页码:")
        p = int(p)
        obj = Pages(p)
    
        print(listfen[obj.start():obj.end()])
        #切片  obj.start()和obj.end()分别获取的是返回值s,e

    #下面是对listfen[obj.start():obj.end() 去括号的操作,在两个方法加@property装饰器

    class Pages:
    
        def __init__(self,nn):
            self.nn = nn          #获取输入的
        @property
        def start(self):
            s = (self.nn-1)*10+1  #分页开始
    
            return s
    
        @property
        def end(self):
            e = self.nn * 10 +1  #分页结束
            return e
    
    listfen=[]
    for li in range(100):
        listfen.append(li)  #添加数据到listfen中
    
    while True:
        p = input("请输入分页码:")
        p = int(p)
        obj = Pages(p)
    
        print(listfen[obj.start:obj.end])
        #切片  obj.start()和obj.end()分别获取的是返回值s,e
  • 相关阅读:
    shell基础之更改IP
    shell基础之if语句
    shell基础之变量及表达式
    shell基础之shell相关概念
    shell基础之bus实战(if 练习)
    shell基础之pxe批量部署
    shell基础之编译安装nginx
    Razor视图引擎基础语法
    EF三层
    EF简单增删改查
  • 原文地址:https://www.cnblogs.com/TKOPython/p/12363245.html
Copyright © 2011-2022 走看看