相关疑难解决方法(0)

Python 3类型检查不能与使用键入模块一起使用?

为什么类型检查在Python 3中不起作用?

我已经使用类型检查或提示完成了以下代码:

import typing

def hello(message: str):
    print(type(message))
    print(message)

hello('Hello!')
hello(1)
hello(1.1)
Run Code Online (Sandbox Code Playgroud)

它产生有效的输出(但int或float上没有错误)。

<class 'str'>
Hello!
<class 'int'>
1
<class 'float'>
1.1
Run Code Online (Sandbox Code Playgroud)

为什么这样工作?也许我不理解输入模块和Python提示。

python python-3.5

4
推荐指数
2
解决办法
1742
查看次数

标签 统计

python ×1

python-3.5 ×1