Python内置 not 函数和bool()函数的简单用法

本文介绍了Python内置的not和bool函数,用于返回布尔值,使代码更加简洁。这两个函数接受Python的各种数据类型作为参数,如整型、列表、字符串和集合。not函数直接对对象进行非运算,bool函数则通过标准的真值测试转换对象。在Python 3.7版本后,bool函数的参数变为位置参数。示例代码展示了它们的简单用法。
摘要由CSDN通过智能技术生成
  • 函数名:not,bool()
  • 作用:返回布尔值,简单用法见代码,可让代码看起来更简洁一些
  • 调用方法:not obj,bool(obj)
  • 参数:
    obj:Python中的各种数据对象,包括整型,列表,字符串,集合等

官方解释:

class bool([x])

Return a Boolean value, i.e. one of True or False. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. The bool class is a subclass of int (see Numeric Types — int, float, complex).

It cannot be subclassed further. Its only instances are False and True (see Boolean Values).

Changed in version 3.7: x is now a positional-only parameter.

operator.not_(obj)
operator.not(obj)

Return the outcome of not obj. (Note that there is no
not() method for object instances; only the interpreter c

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值