Python3基础-语言内置
2015-12-17 16:09
801 查看
Python3基础-语言内置
节选自Python文档的Library Reference部分,位置:Python » 3.4.3 Documentation » The Python Standard Library »
Built-in Functions 内置函数
部分例如:函数 | 例子 |
---|---|
bin() | bin(5) => ‘0b101’ |
chr() | chr(27721) => ‘汉’ |
dict() | |
eval() | x=3, eval(‘x+1’) => 4 |
hex() | |
id() | |
int() | |
len() | |
list() | |
ord() | ord(‘汉’) => 27721 |
range() | |
repr() | repr(100) => ‘100’ |
str() | str(100) => ‘100’ |
tuple() | |
type() | type((6,)) => <class ‘tuple’> |
Built-in Constants 内置常量
TrueFalse
None
NotImplemented
等
Built-in Types 内置类型
Truth Value Testing真值测试
下面的值被当作false看待:None
False
zero of any numeric type, for example,
0,
0.0,
0j.
any empty sequence, for example,
'',
(),
[].
any empty mapping, for example,
{}.
等
Boolean Operations布尔操作
orand
not
Comparisons比较
Operation | Meaning |
---|---|
< | strictly less than |
<= | less than or equal |
> | strictly greater than |
>= | greater than or equal |
== | equal |
!= | not equal |
is | object identity |
is not | negated object identity |
Numeric Types — int, float, complex 三种数值类型
三种数值类型: integers整数, floating point numbers浮点数, and complex numbers复数. In addition, Booleans are a subtype of integers.The constructors
int(),
float(), and
complex()can be used to produce numbers of a specific type.
Bitwise Operations on Integer Types
作用于整数上的位运算:Operation | Result |
---|---|
x l y | bitwise or of x and y |
x ^ y | bitwise exclusive or of x and y |
x & y | bitwise and of x and y |
x << n | x shifted left by n bits |
x >> n | x shifted right by n bits |
~x | the bits of x inverted |
Iterator Types 迭代器类型
略Sequence Types — list, tuple, range 三种序列类型
class list([iterable])
Lists may be constructed in several ways:
Using a pair of square brackets to denote the empty list:
[]
Using square brackets, separating items with commas:
[a],
[a, b, c]
Using a list comprehension:
[x for x in iterable]
Using the type constructor:
list()or
list(iterable)
class tuple([iterable])
Tuples may be constructed in a number of ways:
Using a pair of parentheses to denote the empty tuple:
()
Using a trailing comma for a singleton tuple:
a,or
(a,)
Separating items with commas:
a, b, cor
(a, b, c)
Using the tuple() built-in:
tuple()or
tuple(iterable)
class range(start, stop[, step])
例:
>>> list(range(0, 10, 3)) [0, 3, 6, 9]
Text Sequence Type — str 文本序列类型
Single quotes: ‘allows embedded “double” quotes’Double quotes: “allows embedded ‘single’ quotes”.
Triple quoted: ”’Three single quotes”’, “”“Three double quotes”“”
Binary Sequence Types — bytes, bytearray, memoryview 三种二进制序列类型
略Set Types — set, frozenset 两种集合类型
略Mapping Types — dict 映射类型
略Built-in Exceptions 内置异常
略相关文章推荐
- Python Network Programming(1)---设备名与IPv4地址
- python基础教程_list列表应用
- jy901分发数据+python struct 数据分解
- python串口发送十六进制数
- Python科学计算(一)
- python 去除文本中的URL
- python 简单的单例模式日志模块
- Python基础——yield的使用与解释
- python 发邮件。可以带附件列表
- python3.4学习笔记(四) 3.x和2.x的区别
- 转:python-将字符串转换为字典
- python抓取网页中的链接地址
- python基础知识之—— pip
- Python程序员的10个常见错误
- python编程中的if __name__ == 'main': 的作用和原理
- python安装
- Python 2.7 日期格式化 字符串日期转换
- windows操作系统下,robot+selenimu+python环境搭建
- python 基础知识—— easy_install
- Python-socket总结