博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python bool()函数
阅读量:4170 次
发布时间:2019-05-26

本文共 816 字,大约阅读时间需要 2 分钟。

说明:

>>> help(bool)Help on class bool in module __builtin__:class bool(int) |  bool(x) -> bool |  Returns True when the argument x is true, False otherwise. |  The builtins True and False are the only two instances of the class bool. |  The class bool is a subclass of the class int, and cannot be subclassed.
实例:

#!/usr/bin/env python    #coding:utf-8  #整数0,浮点数0.0,空列表,空元组,空字典,空字符串,均为False  print bool(0.0),bool(0),bool([]),bool(()),bool({}),bool('')#正数,负数均为Trueprint bool(8),bool(-3),bool(-3.9),bool(9.8)#非空列表,非空元组,非空字典,非空字符串均为Trueprint bool([2,3]),bool((3,4)),bool({'name':'song'}),bool('python')
结果:

False False False False False False

True True True True
True True True True

另外,注意:bool是int的子类:

>>> issubclass(bool,int)True>>>

bool类只有True和False两个实例:

>>> isinstance(True,bool)True>>> isinstance(False,bool)True

(完)

转载地址:http://knyai.baihongyu.com/

你可能感兴趣的文章
strace,ltrace linux下跟踪进程调用的命令
查看>>
Linux下简单samba共享配置
查看>>
rh333 - 搭建简易CA中心
查看>>
rh333 - 利用apache搭建简易https服务器
查看>>
adpatch OPTIONS
查看>>
How to get details about patch applied in Oracle Applications by OAM & SQL?
查看>>
配置作为客户机的iptables规则 - ArchLinux
查看>>
Oracle EBS R12 - ad_bugs.BUG_NUMBER和ad_applied_patches.PATCH_NAME的关系
查看>>
rh436 - ssh验证/连接很慢
查看>>
rh436 - Linux下如何根据fdisk/tune2fs -l/dumpe2fs来计算分区的大小
查看>>
高cpu占用sql的诊断流程
查看>>
Archlinux上fcitx怎麼才能輸入正體中文
查看>>
AUTOTRACE与EXPLAIN PLAN,ANALYZE与DBMS_STATS
查看>>
rh442 - Linux下性能监控命令vmstat的简单理解
查看>>
RMAN备份时报“ORA-19504: failed to create file”和“ORA-27038: created file already exists”的一种情况和解决办法
查看>>
rman之resetlogs及恢复备份控制文件的一点理解
查看>>
100 bugs in Open Source C/C++ projects
查看>>
rh436 - 错把“Netmask Bits”当“Netmask”
查看>>
Debian Wheezy 64 - 为Chrome/Chromium和Firefox/Iceweasel添加flash支持
查看>>
rh436 - Facing "Volume group for uuid not found" error while run lvcreate on shared storage
查看>>