如何解决如何只允许 python 类型中的某些字符?
我怎样才能在 python 中做这样的事情?
type something = "a" | "b"
const anotherthing: something = "c" // gives error
此打字稿代码不允许将 anotherthing
的值设置为 a
或 b
以外的任何值,如果我尝试使用任何其他值,它会在 ide 中出现错误.
我怎样才能在 python 中使用这样的东西?
我已经尝试了以下 python 代码。
from typing import Union
something = Union["a","b"]
anotherthing: something = "c" # it does not give any error
我使用 pycharm 作为我的 ide。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。