From ec3541eff9f56d45d97fdb6d20bda9e1aa0a4795 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sat, 31 Oct 2020 19:05:21 -0500 Subject: python PEP484 and PEP526 annotations examples --- annotations.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 annotations.py diff --git a/annotations.py b/annotations.py new file mode 100644 index 0000000..fe48791 --- /dev/null +++ b/annotations.py @@ -0,0 +1,12 @@ +def f(x: float) -> int: + return int(x) + + +print(f.__annotations__['x']) +print(f.__annotations__['return']) + +fname: str = "Kyle" +print(f"fname variable of content 'Kyle' is of type: {__annotations__}") +class Vector2: + x: float # the ": float" annotates variable/name x to hint e.g. pylint that it ought to be a float + y: float \ No newline at end of file -- cgit v1.2.3