PYTHON:一些函数的使用笔记
2013-03-24 20:10
471 查看
1、map内建函数
Help on built-in function map in module __builtin__:
map(...)
map(function, sequence[, sequence, ...]) -> list
Return a list of the results of applying the function to the items of
the argument sequence(s). If more than one sequence is given, the
function is called with an argument list consisting of the corresponding
item of each sequence, substituting None for missing values when not all
sequences have the same length. If the function is None, return a list of
the items of the sequence (or a list of tuples if more than one sequence).
map接收一个函数和一个可迭代对象(如列表)作为参数,用函数处理列表的每个元素,生成并返回新的列表。
例如:map(lambda x: x+2, range(1, 5)) ——> [3, 4, 5, 6]
2、eval内建函数
Help on built-in function eval in module __builtin__:
eval(...)
eval(source[, globals[, locals]]) -> value
Evaluate the source in the context of globals and locals.
The source may be a string representing a Python expression
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
eval(str [,globals [,locals ]])函数将字符串str当成有效Python表达式来求值,并返回计算结果。
exec语句将字符串str当成有效Python代码来执行.提供给exec的代码的名称空间和exec语句的名称空间相同。
execfile(filename [,globals [,locals ]])函数可以用来执行一个文件。
例如:eval('3 + 5') ——> 8
exec('sum = 3 + 5') ——> sum = 8
execfile('test.py') ——> eval test
Help on built-in function map in module __builtin__:
map(...)
map(function, sequence[, sequence, ...]) -> list
Return a list of the results of applying the function to the items of
the argument sequence(s). If more than one sequence is given, the
function is called with an argument list consisting of the corresponding
item of each sequence, substituting None for missing values when not all
sequences have the same length. If the function is None, return a list of
the items of the sequence (or a list of tuples if more than one sequence).
map接收一个函数和一个可迭代对象(如列表)作为参数,用函数处理列表的每个元素,生成并返回新的列表。
例如:map(lambda x: x+2, range(1, 5)) ——> [3, 4, 5, 6]
2、eval内建函数
Help on built-in function eval in module __builtin__:
eval(...)
eval(source[, globals[, locals]]) -> value
Evaluate the source in the context of globals and locals.
The source may be a string representing a Python expression
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
eval(str [,globals [,locals ]])函数将字符串str当成有效Python表达式来求值,并返回计算结果。
exec语句将字符串str当成有效Python代码来执行.提供给exec的代码的名称空间和exec语句的名称空间相同。
execfile(filename [,globals [,locals ]])函数可以用来执行一个文件。
例如:eval('3 + 5') ——> 8
exec('sum = 3 + 5') ——> sum = 8
execfile('test.py') ——> eval test
相关文章推荐
- 笨办法学python笔记:习题11 提问(input()函数使用)
- python中一些函数使用(tile,排序,搜索,计数)
- 九、Python 一些类、实例、内建函数笔记
- [Python学习笔记][第五章Python函数设计与使用]
- python学习笔记10(函数一): 函数使用、调用、返回值
- Python3.3 学习笔记4 - 函数 - 内置和其他一些函数
- Python学习笔记——一些常用函数、常见错误总结
- python学习笔记2:print的使用中的一些问题
- python 一些常用函数笔记
- 阅读源码遇到的一些Python 函数(--小白笔记)
- Python学习笔记(七)函数的使用
- 笔记--python列表及元组以及关于列表操作的函数使用
- Python中函数参数设置及使用的学习笔记
- 树莓派高级GPIO库,wiringpi2 for python使用笔记(二)高精度计时、延时函数
- python 笔记 之 函数的使用
- python一些函数的使用
- R︱sparkR的安装与使用、函数尝试笔记、一些案例
- 机器人概率定位学习笔记第三篇_使用python建立机器人运动函数(move fuction)
- python 中NumPy和Pandas工具包中的函数使用笔记
- python 笔记 之 python2 与python3 的一些差别 及 部分函数