竖线“ |”是什么管道函数自变量类型注释是什么意思?

问题描述

我遇到了这样的签名函数:

// Keys and values held here. 
 myMap = Map<string,mixed>;
 
 const [data,setData] = useState(() => {
    const data = {
      submit: 0,// Set data that I know the keys of here.
    };
    // Set data that I don't know the keys of here.
    // I am trying to dynamically set data[key] as follows (which does not work):
    Object.keys(myMap).forEach(key => data[key] = myMap[key]);
    return data;
  });

是什么意思?

这是我的python 3.8的语法错误。我是否需要从def get_quantile(numbers: List[float],q: float | int ) -> float | int | None : 导入某些内容才能使其正常工作?

解决方法

根据PEP 604|将用于指定Python 3.10中的联合类型。

所以float | int的意思是Union[float,int],即浮点数或整数。

,

表示or。因此,q: float | int意味着q可以是floatint

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...