Python built-in function - bool([x])

本文详细介绍了Python内置bool函数的功能及用法。该函数用于转换输入值为布尔值,即True或False。当输入值为假或为空时,返回False;否则返回True。此外,还提供了多个实例来演示其工作原理。

Python内建函数之class bool([x])

Manual

Return a Boolean value, i.e. one of True or False. x is converted using the standardtruth testing procedure. If x is false or omitted, this returnsFalse; otherwise it returns True. The bool class is a subclass ofint . It cannot be subclassed further. Its only instances areFalse and True.

直译

返回一个布尔值,例如True 或 False之一。‘x'通过使用标准的真值检测程序(好搞siao)— truth testing procedure。如果’x'为否或省略,则返回False;否则返回True。bool类是int子类,它不能进一步划分子类,且仅具有False和True实例。

实例

>>> bool([0])
True
>>> bool([1])
True
>>> bool([False])
True
>>> bool([])
False
>>> bool([''])
True
>>> bool(())
False
>>> bool({})
False
>>> bool((False))
False

拓展阅读

PyTorch built with: - GCC 9.4 - C++ Version: 201703 - OpenMP 201511 (a.k.a. OpenMP 4.5) - LAPACK is enabled (usually provided by MKL) - NNPACK is enabled - CPU capability usage: NO AVX - Build settings: BLAS_INFO=open, BUILD_TYPE=Release, CUDA_VERSION=11.4, CUDNN_VERSION=8.6.0, CXX_COMPILER=/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=1 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=old-style-cast -Wno-invalid-partial-specialization -Wno-unused-private-field -Wno-aligned-allocation-unavailable -Wno-missing-braces -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=open, TORCH_DISABLE_GPU_ASSERTS=ON, TORCH_VERSION=2.1.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EIGEN_FOR_BLAS=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=OFF, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=0, USE_NNPACK=1, USE_OPENMP=ON, USE_ROCM=OFF, (pytorch) jetson@ubuntu:~/miniforge3/envs/pytorch$ ls /usr/local/cuda bin doc extras lib64 README tools compat DOCS gds nvml share version.json compute-sanitizer EULA.txt include nvvm targets (pytorch) jetson@ubuntu:~/miniforge3/envs/pytorch$ nvcc --version 2>/dev/null || echo "nvcc not found, checking alternative methods" nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2024 NVIDIA Corporation Built on Tue_Oct_29_23:53:06_PDT_2024 Cuda compilation tools, release 12.6, V12.6.85 Build cuda_12.6.r12.6/compiler.35059454_0 获取到以上信息,并且nvidia命令无法使用,帮我解决问题
最新发布
09-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值