diff options
author | Kyle K <kylek389@gmail.com> | 2020-10-31 19:05:21 -0500 |
---|---|---|
committer | Kyle K <kylek389@gmail.com> | 2020-10-31 19:05:21 -0500 |
commit | ec3541eff9f56d45d97fdb6d20bda9e1aa0a4795 (patch) | |
tree | 050c09b955dbe65b3c3a471bcd6fd821caac8415 /annotations.py | |
parent | 1cc2e945634759e16e54d46cb5be447759eef75d (diff) | |
download | PythonPractice-ec3541eff9f56d45d97fdb6d20bda9e1aa0a4795.tar.gz PythonPractice-ec3541eff9f56d45d97fdb6d20bda9e1aa0a4795.tar.bz2 PythonPractice-ec3541eff9f56d45d97fdb6d20bda9e1aa0a4795.zip |
python PEP484 and PEP526 annotations examples
Diffstat (limited to 'annotations.py')
-rw-r--r-- | annotations.py | 12 |
1 files changed, 12 insertions, 0 deletions
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 |