feat: 新增技能扩展N5一章相关示例源码

This commit is contained in:
100gle
2022-11-10 09:48:19 +08:00
parent cb8a449048
commit 901f7c10d8
4 changed files with 684 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
class CardGroup:
def __init__(self, container) -> None:
self.container = container
self.index = 0
def __iter__(self):
return self
def __next__(self):
if self.index < len(self.container):
value = self.container[self.index]
self.index += 1
else:
raise StopIteration
return value
class Cards:
def __init__(self, values=None) -> None:
self._container = values or []
def __iter__(self):
return CardGroup(self._container)
def __getitem__(self, index):
return self._container[index]
def main():
from collections.abc import Iterable
cards = Cards(list("JQK"))
print(f"Is the cards variable an iterale? {isinstance(cards, Iterable)}")
for card in cards:
print(card)
print(cards[1:])
if __name__ == '__main__':
main()