gpt4 book ai didi

python - 如何更改内置的 type() 函数?

转载 作者:行者123 更新时间:2023-12-01 23:06:52 24 4
gpt4 key购买 nike

是否可以更改type() 的默认行为?这是现在发生的事情:

simple_string = "this is a simple string"
type(simple_string)
<class 'str'>

这就是我希望它的工作方式或类似的方式:

simple_string = "this is a simple string"
type(simple_string)
"str"

最佳答案

您可以使用__name__ 属性

 simple_string = "this is a simple string"
type(simple_string).__name__

>>> 'str'

关于python - 如何更改内置的 type() 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70717855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com