博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 函数
阅读量:4221 次
发布时间:2019-05-26

本文共 1023 字,大约阅读时间需要 3 分钟。

callable判断 一个东西 是否可以调用。感觉没啥用!!!

>>> x=1>>> import math>>> y=math.sqrt>>> callable(x)False>>> callable(y)True

__doc__

>>> def square(x):	'calculate the square of  the number x'	return x*x>>> square.__doc__'calculate the square of  the number x'>>>
列表传参本质上是指针:

>>> def change(n):	n[0]="asdf"	>>> name=['qqq','bbb']>>> change(name)>>> name['asdf', 'bbb']>>>
全局变量:

>>> x=1>>> def change_global():	global x	x+=1	>>> change_global()>>> x2
bisect模块实现二元查找。

map:

>>> map(str, range(10))>>> list(map(str, range(10)))['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
filter:

>>> seq=['foo', 'x41', '?!', "***"]>>> def func(x):	return x.isalnum()>>> filter(func, seq)
>>> list(filter(func, seq))['foo', 'x41']>>>
>>> [x for x in seq if x.isalnum()]['foo', 'x41']
lambda

>>> filter(lambda x: x.isalnum(), seq)
>>> list(filter(lambda x: x.isalnum(), seq))['foo', 'x41']
reduce:前两个元素与给定的函数联合使用,返回值与第三个元素继续联合使用。

>>> from functools import reduce>>> num=[72, 101, 108, 111, 44, 53]>>> reduce(lambda x,y : x+y, num)489>>>

转载地址:http://nqmmi.baihongyu.com/

你可能感兴趣的文章
HashMap源码分析
查看>>
LinkedList源码分析
查看>>
这个不错!
查看>>
好久不写Qsort了,今天居然编译器不认识,日了!
查看>>
好久不做ACM 做起来手生的很。。
查看>>
对CODEFISH的意见
查看>>
新的构架
查看>>
微软真强啊!这么恶心的model(转自msdn)-----front controller
查看>>
10个月以后 重新开启我的Blog
查看>>
认输了
查看>>
学校的日子
查看>>
我的项目,我的起点
查看>>
决定不逃课了~~~
查看>>
遇到技术问题~~
查看>>
终于弄懂了聊天室的各种技术了
查看>>
母函数算法---组合数学
查看>>
分手快乐---(哪个更好呢)
查看>>
要考试--大敌当前
查看>>
linux 编译技术 6级强化
查看>>
扩大工作室?
查看>>