【Python】【基础知识】【内置常量】
Python的内置常量有:
False、True、None、NotImplemented、Ellipsis、__debug__
由 site 模块添加的常量:quit、exit、copyright、credits、license
内置常量¶
有少数的常量存在于内置命名空间中。 它们是:
False-
bool类型的假值。 给False赋值是非法的并会引发SyntaxError。
True-
bool类型的真值。 给True赋值是非法的并会引发SyntaxError。
None-
NoneType类型的唯一值。None经常用于表示缺少值,当因为默认参数未传递给函数时。 给None赋值是非法的并会引发SyntaxError。
NotImplemented-
二进制特殊方法应返回的特殊值(例如,
__eq__()、__lt__()、__add __()、__rsub__()等)表示操作没有针对其他类型实现;为了相同的目的,可以通过就地二进制特殊方法(例如,__imul __()、__ rightnd__()等)返回。 它的逻辑值为真。注解
当二进制(或就地)方法返回``NotImplemented``时,解释器将尝试对另一种类型(或其他一些回滚操作,取决于运算符)的反射操作。 如果所有尝试都返回``NotImplemented``,则解释器将引发适当的异常。 错误返回的``NotImplemented``将导致误导性错误消息或返回到Python代码中的``NotImplemented``值。
参见 实现算数运算 为例。
注解
NotImplementedError和NotImplemented不可互换,即使它们有相似的名称和用途。 有关何时使用它的详细信息,请参阅NotImplementedError。
Ellipsis-
与省略号文字字面 “
...” 相同。 特殊值主要与用户定义的容器数据类型的扩展切片语法结合使用。
注解
变量名 None,False,True 和 __ debug__ 无法重新赋值(赋值给它们,即使是属性名,将引发SyntaxError ),所以它们可以被认为是“真正的”常数。
由 site 模块添加的常量
site 模块(在启动期间自动导入,除非给出 -S 命令行选项)将几个常量添加到内置命名空间。 它们对交互式解释器 shell 很有用,并且不应在程序中使用。
quit(code=None)exit(code=None)-
当打印此对象时,会打印出一条消息,例如“Use quit() or Ctrl-D (i.e. EOF) to exit”,当调用此对象时,将使用指定的退出代码来引发
SystemExit。
copyrightcredits-
打印或调用的对象分别打印版权或作者的文本。
license-
当打印此对象时,会打印出一条消息“Type license() to see the full license text”,当调用此对象时,将以分页形式显示完整的许可证文本(每次显示一屏)。
————————(我是分割线)————————
一般的内置常量
False、True、None、NotImplemented、Ellipsis、__debug__
False、True 属于bool类型
None 属于
NoneType类型NotImplemented 二进制特殊方法应返回的特殊值
Ellipsis 与省略号文字字面 “
...” 相同。__debug__
>>> __debug__
True如果 Python 没有以
-O选项启动,则此常量为真值。 另请参见assert语句。————————(我是分割线)————————
由
site模块添加的常量quit()
(在Windows环境执行,直接退出PythonIDLE,不过退出之前会弹出确认对话框)

exit()
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> i = 1
>>> print(i)
1
>>> exit
Use exit() or Ctrl-Z plus Return to exit
>>> exit()执行后,弹出确认对话框;

copyright
版权/著作权显示:
>>> copyright
Copyright (c) 2001-2018 Python Software Foundation.
All Rights Reserved. Copyright (c) 2000 BeOpen.com.
All Rights Reserved. Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved. Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.
>>>credits
信誉
>>> credits
Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more information.
>>>感谢 CWI, CNRI, BeOpen.com, Zope Corporation 和数以千计的支持python开发的人员。有关详细信息,请参见www.python.org。
license()
>>> license()
A. HISTORY OF THE SOFTWARE
========================== Python was created in the early 1990s by Guido van Rossum at Stichting
Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands
as a successor of a language called ABC. Guido remains Python's
principal author, although it includes many contributions from others. In 1995, Guido continued his work on Python at the Corporation for
National Research Initiatives (CNRI, see http://www.cnri.reston.va.us)
in Reston, Virginia where he released several versions of the
software. In May 2000, Guido and the Python core development team moved to
BeOpen.com to form the BeOpen PythonLabs team. In October of the same
year, the PythonLabs team moved to Digital Creations, which became
Zope Corporation. In 2001, the Python Software Foundation (PSF, see
https://www.python.org/psf/) was formed, a non-profit organization
created specifically to own Python-related Intellectual Property.
Zope Corporation was a sponsoring member of the PSF. All Python releases are Open Source (see http://www.opensource.org for
the Open Source Definition). Historically, most, but not all, Python
Hit Return for more, or q (and Return) to quit: quit
Hit Return for more, or q (and Return) to quit: q
>>>————————(我是分割线)————————
参考:
1. RUNOOB.COM:https://docs.python.org/zh-cn/3/library/constants.html
备注:
初次编辑时间:2019年9月30日17:55:21
环境:Windows 7 / Python 3.7.2
【Python】【基础知识】【内置常量】的更多相关文章
- Python基础:内置常量
本文根据Python 3.6.5的官文Built-in Constants编写,官文比较短,大家可以直接看原文. 有一些存在于 内置名称空间(the built-in namespace) 的常量,如 ...
- 十六. Python基础(16)--内置函数-2
十六. Python基础(16)--内置函数-2 1 ● 内置函数format() Convert a value to a "formatted" representation. ...
- 十五. Python基础(15)--内置函数-1
十五. Python基础(15)--内置函数-1 1 ● eval(), exec(), compile() 执行字符串数据类型的python代码 检测#import os 'import' in c ...
- Python基础:内置函数
本文基于Python 3.6.5的标准库文档编写,罗列了英文文档中介绍的所有内建函数,并对其用法进行了简要介绍. 下图来自Python官网:展示了所有的内置函数,共计68个(14*4+12),大家可以 ...
- python基础(15):内置函数(一)
1. 内置函数 什么是内置函数? 就是python给你提供的,拿来直接⽤的函数,比如print,input等等,截⽌到python版本3.6.2 python⼀共提供了68个内置函数.他们就是pyth ...
- python基础(内置函数+文件操作+lambda)
一.内置函数 注:查看详细猛击这里 常用内置函数代码说明: # abs绝对值 # i = abs(-123) # print(i) #返回123,绝对值 # #all,循环参数,如果每个元素为真,那么 ...
- Python基础:内置异常(未完待续)
本文根据Python 3.6.5的官文Built-in Exceptions编写,不会很详细,仅对Python的内置异常进行简单(重难点)介绍——很多异常都可以从名称判断出其意义,罗列所有的内置异常. ...
- 第六篇:python基础_6 内置函数与常用模块(一)
本篇内容 内置函数 匿名函数 re模块 time模块 random模块 os模块 sys模块 json与pickle模块 shelve模块 一. 内置函数 1.定义 内置函数又被称为工厂函数. 2.常 ...
- Python基础编程 内置函数
内置函数 内置函数(一定记住并且精通) print()屏幕输出 int():pass str():pass bool():pass set(): pass list() 将一个可迭代对象转换成列表 t ...
- Python基础_内置函数
Built-in Functions abs() delattr() hash() memoryview() set() all() dict() help() min() setat ...
随机推荐
- PHP mysqli_fetch_all() 函数
从结果集中取得所有行作为关联数组: <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localhost ...
- 用CSS实现梯形图标
遇到需要实现如下图标 由图形分析,梯形,平行四边形等都可以由矩形变形而来. 而想要实现梯形,需要进行3D变换,需要使用css3的 perspective属性. 属性 perspective指定了观察者 ...
- CPU内部结构图
原文地址:http://blog.csdn.net/jiuyueguang/article/details/9350793
- [Luogu] 维护序列
https://www.luogu.org/problemnew/show/P2023 线段树双懒标记下放 #include <bits/stdc++.h> using namespace ...
- word标题前出现黑块解决方案
1,将光标定位到出现问题的标题前面 2,点击最上方的标题,然后点击修改-->格式-->编号-->无-->确定. 3,重新设置标题即可.
- golang的写文件测试
package main import ( "os" "strings" "time" "fmt" "strc ...
- 2018-2019-2 20175215 实验四《Android程序设计》实验报告
一.实验内容与步骤 1.任务一:Android Studio的安装测试. 任务要求:参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd) ...
- Vue入门下
使用npm创建项目,系统会自动生成一些列文件. 以慕课网上的Travel项目来说,在生成的项目文件中存在src文件夹,这个文件夹也是平时在做项目的时候用的比较多的,其他的一些配置信息更改的频率较低. ...
- EBS 查看输出HTML报表问题总结
问题一: 请求输出格式为HTML(如下图,默认浏览器输出),希望 查看输出 的时候能够实现excel输出. 解决方法: 路径:系统管理员/安装/浏览器选项 注:维护如下记录 文件格式:HTML ...
- linux中安装python
1.首先切换目录 大型的软件一定要安装在/ opt中 规范 cd /opt 2.下载python3的源码 wget https://www.python.org/ftp/python/3.6.2/P ...