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 方法去判断消息里的值是否设置, ...
随机推荐
- Spring的jdbcTemplate操作
Spring的jdbcTemplate操作 dao层,使用jdbcTemplate Spring对不同的持久化层技术的支持,都进行了封装 JDBC Hibernate5.0 MyBatis JPA 相 ...
- 如何将MagicaVoxel模型导入UE4中(2)
前言 当可以把MagicaVoxel的静态模型导入到UE4后,我又开始不满足了.默认第三人称蓝图的"汽车碰撞人偶(雾)"与场景中的体素画风格格不入,于是,我便想着用自己建造的体素画 ...
- VM虚拟机复制文件问题
需要安装好vmtools,安装好后,启动虚拟机环境: 把需要复制的文件拖进虚拟机环境窗口,鼠标指针会变成复制图标,直接左键即可复制: 不能Ctrl+c-Ctrl+v进去.
- Java基础知识1-Java简介
Java语言技术架构 JAVASE:(Java platform to Standard Edition)标准版,用于桌面级应用开发. JAVAME:(Java plataform to Micro ...
- 曹工说Redis源码(2)-- redis server 启动过程解析及简单c语言基础知识补充
文章导航 Redis源码系列的初衷,是帮助我们更好地理解Redis,更懂Redis,而怎么才能懂,光看是不够的,建议跟着下面的这一篇,把环境搭建起来,后续可以自己阅读源码,或者跟着我这边一起阅读.由于 ...
- Linux基础:Day06
网路安全介绍背景: 早起的互联网 -- 1980年代 ,我们需要共享数据,传输数据:所传输或者共享的数据均为明文: 随着互连网发展,安全称为了国家的一种战略资源: 我们做的,比如编程,运维 -- 手工 ...
- Win 10 C 盘突然爆满,怎么清理?
Win 10 C 盘突然爆满,怎么清理? 使用windows的小伙伴们都知道,C盘是安装系统的,有时候不知道为啥突然就爆满了,查看我的电脑,C盘显示红色的.是不是感觉狠揪心,想删除一些东西有不敢删除, ...
- 微信小程序实现滑动tab切换和点击tab切换并显示相应的数据(附源代码)
这里主要用到了swiper组件和三目运算,直接上代码, 样式只有三个class,简单粗暴,懒的小伙伴们可以直接拿来用,喜欢的点个支持 <view> <view class=" ...
- java第十九天,Collections集合工具类的使用
Collections Java中集合都实现了Collection接口,那么针对集合一些特定的功能,有没有一个接口或类能够统一的集成一些集合必要的功能呢?当然能.它就是--Collections集合工 ...
- python输出中文乱码
首选项-浏览插件目录-USER文件夹 找到编译环境设置,编译方式为UTF-8编码 { "cmd": ["c:/Python36/python.exe",&quo ...