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:
NoneandFalse. - zero of any numeric type:
0,0.0,0j,Decimal(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:
| Operation | Result | Notes |
|---|---|---|
x or y |
if x is false, then y, else x | (1) |
x and y |
if x is false, then x, else y | (2) |
not x |
if x is false, then True, else False |
(3) |
Notes:
- This is a short-circuit operator, so it only evaluates the second argument if the first one is false.
- This is a short-circuit operator, so it only evaluates the second argument if the first one is true.
nothas a lower priority than non-Boolean operators, sonot a == bis interpreted asnot (a == b), anda == not bis a syntax error.
and so on...
12.Python提供了哪些内建类型的更多相关文章
- 2017.7.12 Python的6种内建序列及操作
数据结构是通过某种方式(例如对元素进行编号)组织在一起的数据元素的集合,这些数据元素可以是数字或者字符,甚至可以是其他数据结构. 在Python中,最基本的数据结构是序列(sequence).序列中的 ...
- python高级编程之(类级):子类内建类型
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #类级 #在2.2中,提出了类型(type0与类(class)统一( ...
- dart之旅(二)- 内建类型
目录 number 类型 字符串 布尔类型 像大多数语言一样,dart 也提供了 number,string,boolean 等类型,包括以下几种: numbers strings booleans ...
- Python的四个内置数据类型list, tuple, dict, set
Python语言简洁明了,可以用较少的代码实现同样的功能.这其中Python的四个内置数据类型功不可没,他们即是list, tuple, dict, set.这里对他们进行一个简明的总结. List ...
- Python中3种内建数据结构:列表、元组和字典
Python中3种内建数据结构:列表.元组和字典 Python中有3种内建的数据结构:列表.元组和字典.参考简明Python教程 1. 列表 list是处理一组有序项目的数据结构,即你可以在一个列表中 ...
- 查看Python的版本、内建方法和模块等内容的方法
若想更好地应用Python帮助我们解决日常生活的问题,就必须了解清楚它的内建方法和模块等特性.相信不少同学在安装某个版本的Python后,对于内建方法之类都是一知半解,希望本文能帮助了解Python的 ...
- 零基础学python-4.2 其它内建类型
这一章节我们来聊聊其它内建类型 1.类型type 在python2.2的时候,type是通过字符串实现的,再后来才把类型和类统一 我们再次使用上一章节的图片来说明一些问题 我们通过对照上面的图片.在p ...
- Python的6种内建序列之通用操作
数据结构式通过某种方式(例如对元素进行编号)组织在一起的数据元素的集合,这些数据元素可以是数字或者字符,甚至可以是其他数据结构.在Python中,最基本的数据结构是序列(sequence).序列中的每 ...
- proto3 不支持内建类型的非空判断即 hasXXX
proto3 移除了内建类型的非空判断方法 即代码生成工具不会为 bool int 等类型生成has方法 有使用过proto2 或者其它rpc 框架的人都知道使用has 方法去判断消息里的值是否设置, ...
随机推荐
- iOS, Xcode11,项目提示第三方库报错无法运行 bundle format unrecognized, invalid, or unsuitable
检查你有没有把静态库和动态库配置错误!! 下图处是配置动态库的地方! 对于动态库和静态库都有使用的时候,注意把静态库设置成“Do not Embeded”
- 浅谈动态规划(Dynamic Programming)
利用Leetcode#198打劫家舍 浅谈动态规划 Origin:https://leetcode-cn.com/problems/house-robber/ 题目本身不难,就是一个动态规划的问题.在 ...
- 初识docker与理解
因最近公司的一个新项目,有一个业务场景是需要给多个甲方的服务器配置运行环境与部署,所以考虑使用docker来实现环境配置的统一 1.docker是什么 docker是一种容器虚拟化技术的实现,相当于在 ...
- django rest framework用户认证
django rest framework用户认证 进入rest framework的Apiview @classmethod def as_view(cls, **initkwargs): &quo ...
- alembic的常用参数
alembic的常用参数 命令和参数解释 1 .init:创建一个alembic仓库. 2 .revision:创建一个新的版本文件. 3 .--autogenerate:自动将当前的模型修改,生成迁 ...
- Linux Shell编程,双括号运算符(())
双括号运算符是shell非常强大的扩展. 这里简要介绍两种使用方式: 1.条件判断 跟在if.while.until,for等需要逻辑条件的命令后,进行逻辑判断 if(( expr));then … ...
- ThinkPHP5中raw的作用
在tp5中,我们一般在模板中输出变量是这样的:{$test} 但是有时候在有些源码中我们可以看到这样的方式:{$test|raw} 这个时候如果你去找手册会发现,全文基本没有提到这个raw的作用. 那 ...
- ZooKeeper 如何保证数据一致性?
在分布式场景中,ZooKeeper 的应用非常广泛,比如数据发布和订阅.命名服务.配置中心.注册中心.分布式锁等. 在分布式场景中,ZooKeeper 的应用非常广泛,比如数据发布和订阅.命名服务.配 ...
- ConcurrentHashMap 同步安全 的真正含义(stringbuff 是同步安全的,stringbutter 不安全)
同步安全的集合,在多线程下用到这个map是安全的,但这个安全指的是什么?线程安全指的是指get.remove.put等操作时即同一对象,同一时间只有一个线程能在这几个方法上运行,也就是说线程安全是在这 ...
- Java课程设计之——爬虫篇
主要使用的技术 Httplcient Jsoup 多线程 dao模式 网络爬虫简介 网络爬虫(又称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取 ...