小编dan*_*ore的帖子

将0和1字符串转换为布尔值的最Pythonic方法是什么?

我正在从配置为Input的通用IO(GPIO)中读取一个值,它返回一个0或1的字符串.我看到两种简单的方法将它转换为boolean:

bool(int(input_value))
Run Code Online (Sandbox Code Playgroud)

要么

not not int(input_value)
Run Code Online (Sandbox Code Playgroud)

哪个是Pythonic?有更多的Pythonic方式,然后上面提到的方式?

python

1
推荐指数
1
解决办法
211
查看次数

标签 统计

python ×1