python class 内的 next(),last(),set() 写法卡了一段时间不太知道怎么写,我有一个class 里面需要有next,last,与set()答案要这样:我搞不定- ->d= MyDate(22,10,2012)>s= Schedule(d,usage = "School",owner = "CaCaEgg") # d wil

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/01 07:51:50

python class 内的 next(),last(),set() 写法卡了一段时间不太知道怎么写,我有一个class 里面需要有next,last,与set()答案要这样:我搞不定- ->d= MyDate(22,10,2012)>s= Schedule(d,usage = "School",owner = "CaCaEgg") # d wil
python class 内的 next(),last(),set() 写法
卡了一段时间不太知道怎么写,
我有一个class 里面需要有next,last,与set()
答案要这样:我搞不定- -
>d= MyDate(22,10,2012)
>s= Schedule(d,usage = "School",owner = "CaCaEgg") # d will set as current
>d1= MyDate(29,11,2012)
>d2= MyDate(16,9,2012)
>d3= MyDate(25,9,2012)
>s.add(d1)
>s.add(d2)
>s.add(d3)
>prints.next()
29/11/2012
>prints.last()
25/9/2012
>d= MyDate(20,9,2012)
>s.set(d)
>prints.next()
25/9/2012
>prints.last()
16/9/2012
我的程式码:class Schedule(calender):
def __init__(self,ddate,usage,owner):
self.usage = usage
self.owner = owner
self.current = []
self.current.append(str(ddate))
def __str__(self):
return str(self.current)
def add(self,x):
self.current.append(str(x))
def daylist(self):
return self.current
题目是这样:
请利用继承calender 来解决,请撰写一个Schedule的CLASS,拥有以下members method
members:
current,a MyDateclass
functions:
set(MyDate):set MyDateobject to self.current
next():return the first MyDateobject in daylistafter self.current
last():return the last MyDateobject in daylistbefore self.current

python class 内的 next(),last(),set() 写法卡了一段时间不太知道怎么写,我有一个class 里面需要有next,last,与set()答案要这样:我搞不定- ->d= MyDate(22,10,2012)>s= Schedule(d,usage = "School",owner = "CaCaEgg") # d wil
class Schedule(calender):
    def __init__(self, date, usage, owner):
        self.usage = usage
        self.owner = owner
        # 保存所有的日期
        self._list = [date, ]
        self.current = date
    def add(self, date):
        self._list.append(date)
        # 假定date对象是支持比较的
        self._list.sort()
    def set(self, date):
        if date not in self._list:
            self.add(date)
        self.current = date
    def next(self):
        index = self._list.index(self.current) + 1
        if index >= len(self._list):
            print "no next"
        else:
            return self._list[index]

last类似,略

python class 内的 next(),last(),set() 写法卡了一段时间不太知道怎么写,我有一个class 里面需要有next,last,与set()答案要这样:我搞不定- ->d= MyDate(22,10,2012)>s= Schedule(d,usage = School,owner = CaCaEgg) # d wil 用python 写一组类(class) 对应各种几何体(正方体,长方体,球,圆柱)的表面积和体积的编码 英语翻译monty python 唱的. C和PYTHON的区别 RT,python内建函数,只要全,详,分,PyQt - :Python Lib Reference在哪啊? python map和reduce的用法 请问python中的class如何写出来,比如class c :'fields:a,b' 如果想写一个a=5,b=4的c该怎么写.小弟实在愚钝 Next to class one意思 python括号区别python中,花括号,中括号,小括号的区别在哪里 在python中,如何快速获得闭区间【0,1】的随机数.random()只能获得前闭后开区间[0,1)内的随机数. python问题,我的function不能return,讲的是一个开关灯的类class LightSwitch:def __init__(self,condition):self.is_on = conditionif not isinstance(condition,bool):InvaildSwitchExpection = TypeError(it is not a right state.format(condition python 我想知道这句的具体含义:this only works with two literals,not with arbitrary string express什么是arbitrary string expression,什么事literals,有什么区别Two string literals next to each other are automatically concatenated; t 一道英语首字母填空题(初一的)we will have our class a_____ next monday. we are going to have a class /next week/(对画线的提问) Next,then will (look at our class program.)(对打括号的句子提问) we will have class a____ next Moday Don't be late ( ) class next time 初一英语English class is (relaxing).就括号内的内容提问_________is English class?