python oop_Python OOP --action()函数

importdatetime# Store the next available id for all new noteslast_id=0classNote:'''Represent a note in the notebook. Match against a

string in searches and store tags for each note.'''def__init__(self,memo,tags=''):'''initialize a note with memo and optional

space-separated tags. Automatically set the note's

creation date and a unique id'''self.memo=memo

self.tags=tags

self.creation_date=datetime.date.today()globallast_id

last_id+=1self.id=last_iddefmatch(self,filter):'''Determine if this note matches the filter

text. Return True if it matches, False otherwise.

Search is case sensitive and matches both text and

tags.'''returnfilterinself.memoorfilterinself.tagsclassNotebook:'''Represent a collection of notes that can be tagged,

modified, and searched.'''def__init__(self):'''Initialize a notebook with an empty list.'''self.notes=[]defnew_note(self,memo,tags=''):'''Create a new note and add it to the list.'''self.notes.append(Note(memo,tags))def_find_note(self,note_id):'''Locate the note with the given id.'''fornoteinself.notes:ifstr(note.id)==str(note_id):returnnotereturnNonedefmodify_memo(self,note_id,memo):'''Find the note with the given id and change its

memo to the given value.'''note=self._find_note(note_id)ifnote:note.memo=memoreturnTruereturnFalsedefmodify_tags(self,note_id,tags):'''Find the note with the given id and change its

tags to the given value.'''note=self._find_note(note_id)ifnote:note.tags=tagsreturnTruereturnFalsedefsearch(self,filter):'''Find all notes that match the given filter

string.'''return[notefornoteinself.notesifnote.match(filter)]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值