python函数中文手册

合集下载

Python学习手册.pdf

Python学习手册.pdf

Python学习手册2014/01/16第一部分:使用入门1Python安装与测试1.1下载地址/download/1.2安装注意选择添加系统环境变量1.3测试Win+R>cmd>python2如何运行程序2.1基本语句➢2**8表示2^8;➢Windows下可以使用Ctrl+Z来推出Python。

➢*对于数字来说,表示相乘,对于字符来说表示重复。

不懂得话直接在交互模式下尝试。

➢交互提示模式也是一个测试程组件的地方:引入一个预编码的模块,测试里面的函数,获得当前工作目录的名称。

➢注意缩进(4个空格);➢回车(Enter)两次,多行语句才会执行。

➢执行python,注意文件后缀为.py。

2.2UNIX可执行脚本(#!)➢他们的第一行是特定的。

脚本的第一行往往以字符#!开始(常叫做“hash bang”),其后紧跟着机器Python解释器的路径。

➢他们往往都拥有可执行的权限。

Chmod+x file.py来修改可执行权限。

注意没有后缀名。

Unix下运行命令为:% brain运行结果:The Bright Side of Life…2.3Unix env查找技巧避免硬编码Python解释器的路径,env程序可以通过系统的搜索路径的设置定位Python解释器。

这种方式比2.2中的方法更常用。

2.4Windows下input的技巧在windows系统下,双击script1.py后,会一闪而过,这时候就可以使用input()。

一般来说input读取标准输入的下一行,如果还没有得到输入,就一直等待输入。

从而达到了让脚本暂停的效果。

运行结果:缺陷:看不到错误信息。

2.5模块导入和重载➢每一个以扩展名py结尾的Python源代码文件都是一个模块。

➢其他模块可以通过导入这个模块读取这个模块的基础知识。

➢如上import可以运行,但只是在每次会话的第一次运行,在第一次导入之后,其他的导入都不会再工作。

(这是有意设计的结果,导入是一个开销很大的操作)2.6模块的显要特性:属性作为替代方案,可以通过这样的语句从模块语句中获得变量名:从技术上讲,from 复制了模块的属性,以便属性能够成为接收者的直接变量。

Python中文手册(汉译)Word文字可编辑版

Python中文手册(汉译)Word文字可编辑版

Python 手册Python中文社区Python 手册向上:Python 文档索引向后:前言Python 手册Guido van RossumFred L. Drake, Jr., editorPythonLabsEmail: **********************Release 2.3July 29, 2003前言目录1. 开胃菜2. 使用Python解释器2.1 调用解释器2.1.1 传递参数2.1.2 交互模式2.2 解释器及其工作模式2.2.1 错误处理2.2.2 执行 Python 脚本2.2.3 源程序编码2.2.4 交互环境的启动文件3.初步认识Python3.1 像使用计算器一样使用Python3.1.1 数值3.1.2 字符串3.1.3 Unicode 字符串3.1.4 链表3.2 开始编程4. 流程控制4.1 if 语法4.2 for 语法4.3 range() 函数4.4 break 和continue 语法以及else 子句在循环中的用法4.5 pass 语法4.6 定义函数4.7 定义函数的进一步知识4.7.1 定义参数变量4.7.2 参数关键字4.7.3 可变参数表4.7.4 Lambda 结构4.7.5 文档字符串5. 数据结构5.1 深入链表5.1.1 将链表作为堆栈来使用5.1.2 将链表作为队列来使用5.1.3 函数化的编程工具5.1.4 链表的内含(Comprehensions)5.2 del 语法5.3 Tuples 和 Sequences5.4 字典(Dictionaries)5.5 循环技巧5.6 深入条件控制5.7 Sequences 和其它类型的比较6. 模块6.1 深入模块6.1.1 模块搜索路径6.1.2 “编译” Python 文件6.2 标准模块6.3 dir() 函数6.4 包6.4.1 从包中导入所有内容(import * )6.4.2 隐式包引用6.4.3 包中的多重路径7. 输入和输出7.1 格式化输出7.2 读写文件7.2.1 文件对象的方法7.2.2 pickle 模块8. 错误和异常8.1 语法 Errors8.2 异常8.3 捕获异常8.4 释放异常8.5 用户自定义异常8.6 定义 Clean-up Actions9. 类9.1 一个术语9.2 Python 的生存期和命名空间9.3 类(Classes)的初步印像9.3.1 类定义语法9.3.2 类对象9.3.3 实例对象9.3.4 方法对象9.4 自由标记(Random Remarks)9.5 继承9.5.1 多继承9.6 私有变量9.7 零杂技巧9.8 异常也是类9.9 迭代子(Iterators)9.10 发生器(Generators)10. 接下来?A. 交互式编辑和历史回溯A.1 行编辑A.2 历史回溯A.3 快捷键绑定A.4 注释B. 浮点计算:问题与极限B.1 表达错误C. 历史和授权C.1 本软件的历史C.2 修改和使用Python的条件(Terms and conditions for accessing or otherwise usingPython)关于本文档Python 手册向上:Python 文档索引向后:前言Release 2.3, documentation updated on July 29, 2003.See A bout this document... for information on suggesting changes.Python中文社区前言Python中文社区Python 指南向前:Python 指南向上: P ython 指南向下:目录前言Copyright © 2001, 2002, 2003 Python Software Foundation. All rights reserved.Copyright © 2000 . All rights reserved.Copyright © 1995-2000 Corporation for National Research Initiatives. All rights reserved.Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.See the end of this document for complete license and permissions information.概要:Python 是一种容易学习的强大语言。

python 函数说明

python 函数说明

python 函数说明Python一种强大的、面向对象的编程语言,它具有开放、灵活、可扩展的特点。

而函数是编程语言中最重要的一部分,从现在起,我们将详细介绍 Python数的定义、调用和使用,旨在帮助更多开发者更好地理解Python函数。

一、Python函数的定义Python数是一个可以重复使用的程序段,它由一个函数名称和一个或多个参数组成,并以def关键字开头,以:结尾,其结构如下: def数名(参数列表):数体例如:def add(x,y):return x+y函数体中定义需要执行的代码,但函数体一律为块级范围,同一个函数体中需要使用相同的缩进,以便阅读和理解。

二、Python函数的调用调用函数就是使用函数,它是运行函数体中的代码,以便实现特定的功能。

调用函数的形式:函数名(参数列表)。

例如:add(2,3)调用函数后,Python可以根据参数列表,计算出一个结果或者返回一个值,例如上面示例中,调用add函数返回结果为5。

三、Python函数使用使用函数可以提高代码的可维护性、可扩展性和复用性,以更高效的方式编写程序,Python的函数使用有以下几种情况:(1)函数带参数使用有时候,希望对函数的功能进行调整或者定制化,就需要使用参数。

参数就是初始化函数的执行过程,来实现字段、变量等的调整,能够有效的定制个性化功能。

例如:def add(x,y):return x+y+2上面这个例子中,用到了参数,将函数add中的表达式修改为x+y+2,这就实现了个性化的功能。

(2)函数嵌套使用在Python中,定义的函数可以再次被另一个函数调用,这就是嵌套使用。

通过嵌套使用函数,可以减少代码重复率,提高程序运行效率,让程序结构更加清晰。

例如:def add(x,y):return x+ydef sum(x,y,z):return add(x,y)+z上面的例子中,sum函数调用了add函数,减少了add函数的代码重复,使两个函数各自执行所需的功能。

python常用函数手册

python常用函数手册

python常用函数手册Python是一种功能强大且灵活的编程语言,具有丰富的内置函数和标准库。

以下是一些常用的Python内置函数的手册:1. `print()`: 用于打印输出内容到控制台。

2. `input()`: 用于从用户处获取输入。

3. `len()`: 返回对象的长度或项目数。

4. `type()`: 返回对象的类型。

5. `int()`: 将一个字符串或数字转换为整数。

6. `float()`: 将一个字符串或数字转换为浮点数。

7. `str()`: 将指定的值转换为字符串。

8. `list()`: 将一个可迭代的对象转换为列表。

9. `dict()`: 创建一个新的字典。

10. `max()`: 返回给定参数的最大值。

11. `min()`: 返回给定参数的最小值。

12. `sum()`: 返回可迭代对象的总和。

除了上述内置函数外,Python标准库也提供了许多常用的函数,比如:1. `os`: 提供了访问操作系统服务的功能。

2. `math`: 提供了数学运算相关的函数。

3. `random`: 用于生成随机数。

4. `datetime`: 用于处理日期和时间。

5. `json`: 用于处理JSON数据。

此外,Python还有许多第三方库,这些库提供了各种各样的函数和工具,比如`numpy`用于科学计算,`pandas`用于数据分析,`requests`用于发送HTTP请求等等。

总之,Python拥有丰富的内置函数和标准库,同时也有大量的第三方库可供使用,开发者可以根据自己的需求选择合适的函数和库来完成各种任务。

Python-3.5.2--官方入门指南-中文版

Python-3.5.2--官方入门指南-中文版

Python 入门指南目录Python 入门指南 (1)1. 开胃菜 (5)2. 使用Python 解释器 (6)2.1. 调用Python 解释器 (6)2.1.1. 参数传递 (8)2.1.2. 交互模式 (8)2.2. 解释器及其环境 (8)2.2.1. 源程序编码 (8)3. Python 简介 (9)3.1. 将Python 当做计算器 (10)3.1.1. 数字 (10)3.1.2. 字符串 (12)3.1.3. 列表 (16)3.2. 编程的第一步 (18)4. 深入Python 流程控制 (19)4.1. if 语句 (20)4.2. for 语句 (20)4.3. range() 函数 (21)4.4. break 和continue 语句, 以及循环中的else 子句 (22)4.5. pass 语句 (23)4.6. 定义函数 (24)4.7. 深入Python 函数定义 (26)4.7.1. 默认参数值 (26)4.7.2. 关键字参数 (28)4.7.3. 可变参数列表 (30)4.7.4. 参数列表的分拆 (30)4.7.5. Lambda 形式 (31)4.7.6. 文档字符串 (31)4.7.7. 函数注解 (32)4.8. 插曲:编码风格 (33)5. 数据结构 (34)5.1. 关于列表更多的内容 (34)5.1.1. 把列表当作堆栈使用 (35)5.1.2. 把列表当作队列使用 (36)5.1.3. 列表推导式 (37)5.1.4. 嵌套的列表推导式 (39)5.2. del 语句 (40)5.3. 元组和序列 (40)5.4. 集合 (42)5.6. 循环技巧 (44)5.7. 深入条件控制 (46)5.8. 比较序列和其它类型 (46)6. 模块 (47)6.1. 深入模块 (48)6.1.1. 作为脚本来执行模块 (49)6.1.2. 模块的搜索路径 (50)6.1.3. “编译的” Python 文件 (51)6.2. 标准模块 (51)6.3. dir() 函数 (52)6.4. 包 (55)6.4.1. 从* 导入包 (57)6.4.2. 包内引用 (58)6.4.3. 多重目录中的包 (58)7. 输入和输出 (58)7.1. 格式化输出 (59)7.1.1. 旧式的字符串格式化 (63)7.2. 文件读写 (63)7.2.1. 文件对象方法 (63)7.2.2. 使用json 存储结构化数据 (66)8. 错误和异常 (67)8.1. 语法错误 (67)8.2. 异常 (67)8.3. 异常处理 (68)8.4. 抛出异常 (71)8.5. 用户自定义异常 (71)8.6. 定义清理行为 (73)8.7. 预定义清理行为 (74)9. 类 (75)9.1. 术语相关 (75)9.2. Python 作用域和命名空间 (76)9.2.1. 作用域和命名空间示例 (78)9.3. 初识类 (78)9.3.1. 类定义语法 (79)9.3.2. 类对象 (79)9.3.3. 实例对象 (80)9.3.4. 方法对象 (81)9.3.5. 类和实例变量 (82)9.4. 一些说明 (83)9.5. 继承 (85)9.5.1. 多继承 (86)9.6. 私有变量 (87)9.7. 补充 (88)9.9. 迭代器 (89)9.10. 生成器 (91)9.11. 生成器表达式 (91)10. Python 标准库概览 (92)10.1. 操作系统接口 (92)10.2. 文件通配符 (93)10.3. 命令行参数 (93)10.4. 错误输出重定向和程序终止 (93)10.5. 字符串正则匹配 (94)10.6. 数学 (94)10.7. 互联网访问 (95)10.8. 日期和时间 (95)10.9. 数据压缩 (96)10.10. 性能度量 (96)10.11. 质量控制 (97)10.12. “瑞士军刀” (98)11. 标准库浏览– Part II (98)11.1. 输出格式 (98)11.2. 模板 (100)11.3. 使用二进制数据记录布局 (101)11.4. 多线程 (102)11.5. 日志 (103)11.6. 弱引用 (103)11.7. 列表工具 (104)11.8. 十进制浮点数算法 (105)12. 虚拟环境和包 (106)12.1. 简介 (106)12.2. 创建虚拟环境 (107)12.3. 使用pip 管理包 (108)13. 接下来? (110)14. 交互式输入行编辑历史回溯 (112)14.1. Tab 补全和历史记录 (112)14.2. 其它交互式解释器 (112)15. 浮点数算法:争议和限制 (112)15.1. 表达错误 (116)16. 附录 (118)16.1. 交互模式 (118)16.1.1. 错误处理 (118)16.1.2. 可执行Python 脚本 (118)16.1.3. 交互式启动文件 (119)16.1.4. 定制模块 (119)Python 是一门简单易学且功能强大的编程语言。

python函数手册中文

python函数手册中文

python函数手册中文Python函数手册是一份非常重要的参考资料,它详细介绍了Python编程语言中各种函数的用法、参数以及返回值等信息。

以下是对Python函数手册的多角度全面回答。

首先,Python函数手册提供了Python内置函数的详细说明。

Python内置函数是指在Python解释器中直接可用的函数,例如print()、len()、range()等。

手册会解释这些函数的功能、参数以及使用示例,帮助开发者更好地理解和使用这些常用函数。

其次,Python函数手册还包括了标准库函数的介绍。

标准库是Python提供的一组功能强大的模块集合,涵盖了各种领域,例如字符串处理、文件操作、网络通信等。

手册会列举标准库中的常用函数,并详细说明它们的用法和参数。

这些函数的使用可以极大地提高开发效率,因此对于Python开发者来说,掌握标准库函数是非常重要的。

此外,Python函数手册还包含了第三方库函数的介绍。

Python拥有一个庞大的第三方库生态系统,其中包含了各种强大的功能库,例如NumPy、Pandas、Matplotlib等。

手册会对这些库中的函数进行详细的解释,帮助开发者了解其功能和使用方法。

这些库函数的使用可以大大拓展Python的功能范围,使得开发者能够更加便捷地完成各种任务。

此外,Python函数手册还会介绍一些常用的编程技巧和最佳实践。

这些技巧和实践可以帮助开发者写出更加高效、可读性更强的代码。

手册会提供一些示例代码和解释,帮助开发者理解这些技巧的原理和用法。

总结起来,Python函数手册是一份非常重要的参考资料,它详细介绍了Python中各种函数的用法、参数和返回值等信息。

通过学习和掌握这些函数,开发者可以更加高效地进行Python编程,并写出功能强大、可读性好的代码。

python常用函数及模块

python常用函数及模块

python常⽤函数及模块原⽂来源于博客园和CSDN1.计算函数abs()--取绝对值max()--取序列最⼤值,包括列表、元组min()--取序列最⼩值len()--取长度divmod(a,b)---取a//b除数整数以及余数,成为⼀个元组pow(x,y)--取x的Y次幂pow(x,y,z)先x的Y次幂,再对Z取余round()--修改精度,如果没有,默认取0位range()快速⽣成⼀个列表2.其他函数callable()--返回是否可调⽤返回true或falseisinstance(a,type)---判断前⾯的是否是后⾯的这种类型,返回true或falsecmp(a,b)---判断ab是否相等,相等返回0,A<B返回-1,A>B返回1range()--快速⽣成⼀个列表,类型为listxrange()---快速⽣成⼀个列表,类型为xrange3.类型转换函数type()int()long()float()complex()--转换成负数hex()--转换成⼗六进制oct()--转换成⼋进制chr()--参数0-252,返回当前的ASCII码ord()--参数ASCII码,返回对应的⼗进制整数4.string函数str.capitalize()--对字符串⾸字母⼤写str.replace(a.b)---对字符串a改为bstr.split()---对字符串进⾏分割,第⼀个参数是分隔符,后⾯参数是分割⼏次。

string函数导⼊使⽤5.序列函数filter()--筛选返回为true返回成序列lambda--定义函数zip()---对多个列表进⾏压缩组合成⼀个新列表,但是如果多个列表的元素个数不同,组合的结果按最少元素的进⾏组合map--对多个列表进⾏压缩组合成⼀个新列表,但是如果多个列表的元素个数不同,结果是将所有的元素取出来,缺少的以None代替。

如果是None,直接组合,如果是函数,可以按函数进⾏组合reduce()--对每个元素先前两个执⾏函数,然后结果和后⼀个元素进⾏函数操作,如阶乘,阶加----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------urlencode与urldecode当url中包含中⽂或者参数包含中⽂,需要对中⽂或者特殊字符(/、&)做编码转换。

资料python函数中文手册练习

资料python函数中文手册练习

资料python函数中文手册练习一、选择题1.检测输入的四位整数abcd是否满足下述关系:(ab+cd)(ab+cd)=abcd。

实现上述功能的python程序代码如下:k=int(input(“输入一个四位数:”))①y=k%100if ② :print(“符合”)else:print(“不符合”)划线处应填入的代码是()A.①x=k/100 ②(x+y)*2!=k B.①x=k//100 ②(x+y)*2==kC.①x=k/100 ②(x+y)**2!=k D.①x=k//100 ②(x+y)**2==k2.下列属于正确的Python变量名的是()A.TrueB.88abcC.abc&88D._abc883.在Python中要交换变量a和b中的值,应使用的语句组是()A.a,b = b,a B.a = c ;a = b;b = cC.a = b;b = a D.c = a;b = a;b = c4.下列选项中,可以作为 Python程序变量名的是()A.a/b B.ab C.a+b D.a-b5.python语言的特点()。

A.简单B.免费、开源C.可移植性D.以上都是6.在Python中print(8+7%2**2)的执行结果是()A.5 B.1 C.6 D.117.在Python中,表达式(21%4)+5的值是()A.2 B.6 C.10 D.38.关于Python3.8基础知识的说法中,不正确的是()A.支持中文做标识符B.Python标识符不区分字母的大小写C.Python命令提示符是>>>D.命令中用到的标点符号只能是英文字符9.下列选项中,合法的Python变量名是()A.print B.speed C. D.a#210.在Python中,已知a=3,b=5,运行下列程序段后,a和b的值为a = a * bb = a // ba = a // bA.a=3 b=5 B.a=15 b=3 C.a=5 b=5 D.a=5 b=311.运行下列Python程序,输出结果为0,则空白处应为()a=14b=7c=_______print(c)A.a-b B.a+b C.a/b D.a%b12.下列序列拼接错误的是()A.list = [ None ] * 4B.msg = “Python”, ”语言”C.tup = “/”.join( ( “123”, ”234” ) )D.set = { 1, 2, 3 } + { 4, 5, 6 }13.把数式写成Python语言的表达式,下列书写正确的是()。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

内置函数一,文档说明原始文档来自于python v2.7.2中文译文和用法尚不完全,您可以自由修改和完善,您可以在文档结尾鸣谢添上您的名字,我们将会感谢您做的贡献!二,函数列表1,取绝对值abs(x)Return the absolute value of a number. The argument may be a plain or long integer or a floating point number. If the argument is a complex number, its magnitude is returned.如果你不知道绝对值什么意思,那就要补一下小学数学了!基本用法2,all(iterable)Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to:3.any(iterable)Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to:4.basestring()This abstract type is the superclass for str and unicode. It cannot be called or instantiated, but it can be used to test whether an object is an instance of str or unicode. isinstance(obj,basestring) is equivalent to isinstance(obj,(str,unicode)).是字符串和字符编码的超类,是抽象类型。

不能被调用或者实例化。

可以用来判断实例是否为字符串或者字符编码。

方法:5.二进制转换bin(x)Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.转换成二进制表达方法:6.布尔类型bool([x])Convert a value to a Boolean, using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True布尔类型的转化用法:7. 二进制数组的转化bytearray([source[, encoding[, errors]]])Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the str type has, see String Methods.The optional source parameter can be used to initialize the array in a few different ways:•If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then convertsthe string to bytes using str.encode().•If it is an integer, the array will have that size and will be initialized with null bytes.•If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize thebytes array.•If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contentsof the array.Without an argument, an array of size 0 is created.8.callable(object)Return True if the object argument appears callable, False if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); class instances are callable if they have a __call__() method.9.数字转化成字符chr(i)Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range. See also unichr().用法:10.classmethod(function)Return a class method for function.A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:11.两两比较cmp(x, y)Compare the two objects x and y and return an integer according to the outcome. The return value is negative if x < y, zero if x == y and strictly positive if x > y.X小于X输出负(-1),X等于Y输出零(0),X大于Y输出正(1)用法:12.compile(source, filename, mode[, flags[, dont_inherit]])Compile the source into a code or AST object. Code objects can be executed by an exec statement or evaluated by a call to eval(). source can either be a string or an AST object. Refer to the ast module documentation for information on how to work with AST objects.13.complex([real[, imag]])Create a complex number with the value real + imag*j or convert a string or number to a complex number. If the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. The second parameter can never be a string. Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the function serves as a numeric conversion function like int(), long() and float(). If both arguments are omitted, returns 0j.14.delattr(object, name)This is a relative of setattr(). The arguments are an object and a string. The string must be the name of one of the object’s attributes. The function deletes the named attribute, provided the object allows it. For example, delattr(x, 'foobar') is equivalent to del x.foobar.15.字典dict([arg])Create a new data dictionary, optionally with items taken from arg.The dictionary type is described in Mapping Types — dict.For other containers see the built in list, set, and tuple classes, and the collections module.16.很重要的函数,属性输出dir([object])Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.方法17.divmod(a, b)Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division. With mixed operand types, the rules for binary arithmetic operators apply. For plain and long integers, the result is the same as (a // b, a % b). For floating point numbers the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that. In any case q * b + a %b is very close to a, if a % b is non-zero it has the same sign as b, and0 <= abs(a % b) < abs(b).18.enumerate(sequence[, start=0])Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration. The next() method of the iterator returned by enumerate()returns a tuple containing a count (from start which defaults to 0) and the corresponding value obtained from iterating over iterable. enumerate() is useful for obtaining an indexed series: (0, seq[0]), (1, seq[1]), (2, seq[2])19.eval(expression[, globals[, locals]])The arguments are a string and optional globals and locals. Ifprovided, globals must be a dictionary. If provided, locals can be any mapping object.Changed in version 2.4: formerly locals was required to be adictionary.execfile(filename[, globals[, locals]])This function is similar to the exec statement, but parses a file instead of a string. It is different from the import statement in that it does not use the module administration — it reads the file unconditionally and does not create a new module.和exec很相似的函数21.file(filename[, mode[, bufsize]])Constructor function for the file type, described further in section File Objects. The constructor’s arguments are the same as those of the open() built-in function described below.When opening a file, it’s preferable to use open() instead of invoking this constructor directly. file is more suited to type testing (for example, writing isinstance(f, file)).22.filter(function, iterable)Construct a list from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If iterable is a string or a tuple, the result also has that type; otherwise it is always a list.If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.Note that filter(function, iterable) is equivalent to [item for item in iterable if function(item)] if function is not None and [item for item in iterable if item] if function is None.See itertools.ifilter()and itertools.ifilterfalse()for iterator versions of this function, including a variation that filters for elements where the function returns false.23.浮点数值转化float([x])用法:format(value[, format_spec])Convert a value to a “formatted” rep resentation, as controlled by format_spec. The interpretation of format_spec will depend on the type of the value argument, however there is a standard formatting syntax that is used by most built-in types: Format Specification Mini-Language.25frozenset([iterable])Return a frozenset object, optionally with elements taken from iterable. The frozenset type is described in Set Types — set, frozenset.For other containers see the built in dict, list, and tuple classes, and the collections module.26.getattr(object, name[, default])Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised.27.全局参数globals()Return a dictionary representing the current global symbol table. This is always the dictionary of the current module (inside a function or method, this is the module where it is defined, not the module from which it is called).28.hasattr(object, name)Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).29.hash(object)Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).30.很重要的帮助函数方法help([object])31.十六进制转化hex(x)Convert an integer number (of any size) to a hexadecimal string. The result is a valid Python expression.用法:32.内存地址id(object)Return the “identity” of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.如果想知道某个对象的内存地址,用这个内置函数,返回的是10进制的地址。

相关文档
最新文档