zoukankan      html  css  js  c++  java
  • 12.Python提供了哪些内建类型

    There are mutable and Immutable types of Pythons built in types Mutable built-in types:

    List

    Set

    Dictionary

    Immutable built-in types:

    String

    Tuple

    Number

    Built-in Types:https://docs.python.org/dev/library/stdtypes.html

    主要的内置类型:

      numerics, sequences, mappings, classes, instances and exceptions

      数字、序列、映射、类、实例和异常。

    mutable built-in types,可以add, subtract, rearrange their numbers in place。

    1.Truth Value Testing

    Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below.

    By default, an object is considered true unless its class defines either a __bool__() method that returns False or a __len__() method that returns zero, when called with the object. [1]Here are most of the built-in objects considered false:

    • constants defined to be false: None and False.
    • zero of any numeric type: 00.00jDecimal(0)Fraction(0, 1)
    • empty sequences and collections: ''()[]{}set()range(0)

    Operations and built-in functions that have a Boolean result always return 0 or False for false and 1 or True for true, unless otherwise stated. (Important exception: the Boolean operations or and and always return one of their operands.)

    布尔值True or False:

    默认情况下,除非一个对象的__bool__()方法返回的是False,__len__()方法返回值为0,其他情况下的对象默认返回的bool值为True.

    下面是常见的内置对象被默认为False的情况:

    • None 或 False
    • 0值
    • 空值,空集合等

    2.Boolean Operations--and,or,not

    These are the Boolean operations, ordered by ascending priority:

    OperationResultNotes
    or y if x is false, then y, else x (1)
    and y if x is false, then x, else y (2)
    not x if x is false, then True, else False (3)

    Notes:

    1. This is a short-circuit operator, so it only evaluates the second argument if the first one is false.
    2. This is a short-circuit operator, so it only evaluates the second argument if the first one is true.
    3. not has a lower priority than non-Boolean operators, so not == b is interpreted as not (a == b), and == not b is a syntax error.

    and so on...

  • 相关阅读:
    xamarin ios html5 video.js 无法播放
    限制WPF textbox 字符最大值
    .net 客户端 WCF Binding 多次迭代
    10款无需编程的App DIY开发工具
    国外一些好用的UX/UI设计工具和资源分享
    成功网页设计师的七大必备技能
    提升编程能力的11个技巧
    2015程序员推荐书单
    前端工作流程自动化——Grunt/Gulp 自动化
    HTML5初学者福利!11个在线学习网站推荐
  • 原文地址:https://www.cnblogs.com/zoe233/p/7424686.html
Copyright © 2011-2022 走看看