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...

  • 相关阅读:
    cookie和session学习笔记
    Listener和Filter学习笔记
    [转载]mysql root密码忘了怎么办
    [转载]oracle连不上的各种现象
    Oauth入门学习
    XML学习笔录
    共享内存
    守护进程
    Linux系统调用与文件I/O(一)
    我的第一篇博客
  • 原文地址:https://www.cnblogs.com/zoe233/p/7424686.html
Copyright © 2011-2022 走看看