Python 3.14 • WASM
LOADING…
실행 (Ctrl+Enter)
출력 지우기 (Ctrl+L)
Editor
import sys from dataclasses import dataclass from math import pi from pathlib import Path from functools import lru_cache from html import escape as _html_escape print(f"[python] {sys.version.split()[0]}") try: from string.templatelib import Template, Interpolation except Exception: Template = None Interpolation = None def render_html(template): out=[] for part in template: if isinstance(part,str): out.append(part) else: v=part.value c=getattr(part,"conversion",None) fs=getattr(part,"format_spec","") if c=="r": v=repr(v) elif c=="a": v=ascii(v) elif c=="s": v=str(v) if fs: v=format(v,fs) out.append(_html_escape(str(v),quote=True)) return "".join(out) name="파이썬"; score=99.456 if Template: html=render_html(t"
{name!s}
— π≈{pi:.3f}, score={score:.1f}") print(f"[tstr] {html}") else: print("[tstr] unavailable") try: from annotationlib import get_annotations, Format except Exception: get_annotations=None class Format: VALUE=STRING=FORWARDREF=object() def needs_tree(n:"Tree")->int: return 1 @dataclass(slots=True,kw_only=True) class Tree: value:int child:"Tree|None"=None if get_annotations: try: print("[ann] VALUE",get_annotations(needs_tree,format=Format.VALUE)) except Exception as e: print("[ann] VALUE error:",type(e).__name__) print("[ann] FORWARDREF",get_annotations(needs_tree,format=Format.FORWARDREF)) print("[ann] STRING",get_annotations(needs_tree,format=Format.STRING)) else: print("[ann] unavailable") def parse_int(x): try: return int(x) except (ValueError,TypeError): return None print("[except]",parse_int("10"),parse_int(None)) @dataclass(slots=True,kw_only=True) class Point: x:int y:int tag:str="P" def where(p:Point)->str: match p: case Point(x=0,y=0): return "origin" case Point(x=0,y=_): return "y-axis" case Point(x=_,y=0): return "x-axis" case Point(x=a,y=b) if a==b: return "y=x" case _: return "somewhere" print("[match]",where(Point(x=3,y=3))) def top_k[T:(int,float)](xs:list[T],k:int)->list[T]: return sorted(xs)[-k:] print("[generic]",top_k([1,9,4,7],2)) @lru_cache(maxsize=None) def fib(n:int)->int: return n if n<2 else fib(n-1)+fib(n-2) print("[cache] fib(10) =",fib(10)) p=Path("sample.txt") p.write_text("hello, 3.14!\n",encoding="utf-8") print("[path]",p.resolve().name,"→",p.read_text(encoding="utf-8").strip())
단축키: Ctrl+Enter 실행 · Ctrl+L 출력 지우기
Output