Python3基础-语言内置

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值