网站not found,wordpress默认居中,wordpress可视化功能,响应式网页制作场景这要是讲函数注释的用法没有返回值def function(ver: str):print(var)单个返回值def function(ver: str) - dict:a[ver,ver,ver]return a多个返回值您总是返回一个对象#xff1b;使用return one, two只返回一个元组。所以是的#xff0c;- Tuple[bool, str] 完全…场景这要是讲函数注释的用法没有返回值def function(ver: str):print(var)单个返回值def function(ver: str) - dict:a[ver,ver,ver]return a多个返回值您总是返回一个对象使用return one, two只返回一个元组。所以是的- Tuple[bool, str] 完全正确。只有类型Tuple允许您指定元素的固定数量每个元素都有一个不同的类型。如果函数生成的返回值数目是固定的值尤其是当这些值是特定的、不同的类型时则应该始终返回元组。from typing import Tupledef function(ver: str) - Tuple[str, str, bool]:averbBBBcTruereturn a, b, cA,B,Cfunction(hello)print(A)print(B)print(C)其他序列类型对于可变数量的元素应该有one类型规范因此typing.Sequence在这里不合适。另见 Whats the difference between lists and tuples?Tuples are heterogeneous data structures (i.e., their entries have different meanings), while lists are homogeneous sequences. Tuples have structure, lists have order.Python 的类型提示系统遵循这一原则目前没有语法来指定固定长度的iterable并且在特定位置包含特定类型。如果您必须指定任何iterable都可以那么最好的方法是- Iterable[Union[bool, str]]此时调用者可以期望布尔值和字符串以任意顺序长度未知(介于0和无穷大之间)。