Update README.md

Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
David Rotermund 2023-11-23 18:58:23 +01:00 committed by GitHub
parent da54fa7112
commit c67be1599e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,5 +36,31 @@ Variables are assigned to a type the ***first*** time when used or can be define
a: int
b: int = 0
```
You are allowed to connect a variable ***once and only once*** to a type. If you assign a type a second time to a variable then you will get an error and have to remove the second assignment.
For functions it looks a bit different because we have to handle the type of the return value with the **->** construct:
```python
def this_is_a_function() -> None:
pass
def this_is_a_function() -> int:
return 5
def this_is_a_function(a: int) -> int:
return a
def this_is_a_function(a: int, b: int = 8) -> int:
return a + b
def this_is_a_function(a: int, b: int = 8) -> tuple[int, int]:
return a, b
```
Please note, that there is a difference how type annotations worked for older version. I will cover only Python 3.10 and newer.
## MyPy under VS Code
(also the header packages)