penguin-wwy / magic-in-ten-mins-py Goto Github PK
View Code? Open in Web Editor NEW十分钟魔法练习 Python 版
License: Creative Commons Attribution 4.0 International
十分钟魔法练习 Python 版
License: Creative Commons Attribution 4.0 International
py 的枚举类比较弱。所以需要用 Union 或者 | 来表达和类型。(利用继承的思路学到了)
from __future__ import annotations
import enum
from dataclasses import dataclass
from typing import Union
@dataclass
class Student:
name: str
id: int
@dataclass
class Teacher:
name: str
office: str
SchoolPerson = Union[Student, Teacher]
class Bool(enum.Enum):
TRUE = enum.auto()
FALSE = enum.auto()
def test_bool():
b = Bool.FALSE
match b:
case Bool.TRUE:
...
case Bool.FALSE:
print("oh my?")
test_bool()
@dataclass
class O:
...
@dataclass
class S:
x: Nat
def __repr__(self) -> str:
def count(x: Nat):
match x:
case S(x):
return 1 + count(x)
case O():
return 0
return str(count(self))
Nat = S | O
print(S(S(S(S(O())))))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.