您的位置:首页 > 编程语言 > Python开发

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 内置常量

True

False

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布尔操作

or

and

not

Comparisons比较

OperationMeaning
<strictly less than
<=less than or equal
>strictly greater than
>=greater than or equal
==equal
!=not equal
isobject identity
is notnegated 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

作用于整数上的位运算:

OperationResult
x l ybitwise or of x and y
x ^ ybitwise exclusive or of x and y
x & ybitwise and of x and y
x << nx shifted left by n bits
x >> nx shifted right by n bits
~xthe 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, c
or
(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 内置异常

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: