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
原文地址:https://www.cnblogs.com/TKOPython/p/12363245.html
时间: 2024-10-10 05:34:04