[Python] Use Static Typing in Python 3.6

In this lesson, you will learn how to statically type variables in Python 3.6 Static typing can help you avoid errors when consumers of your variables and functions call them with the incorrect data type. You will learn how to statically type strings, integers, booleans, Lists and Dicts. You will also learn how to automatically check for typing errors when coding and as part of your build workflow.

from typing import Dict, List


def add_num(a: int, b: int):
    return a + b


my_string: str

my_bool: bool


my_nums: List[int]

my_dict: Dict[str, int] = {
    "Patriots": 23,
    "Falcons": 7
}
原文地址:https://www.cnblogs.com/Answer1215/p/9065407.html