2 Star 1 Fork 0

Emma/pythonStudy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
4.py 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
Tom 提交于 2022-10-01 20:27 . 3~6
from functools import reduce
from turtle import pensize
def f(x):
return x*x
r = map(f,[1,2,3,4,5,6,7,8,9])
print(list(r))
def fn(x,y):
return x*10+y
print(reduce(fn,[1,2,3,4,5]))
def is_odd(x):
return x&1 ==0
print(list(filter(is_odd,[1,2,3,4,5,6,7,8])))
print(sorted([36,5,-12,9,-21]))
print(sorted([36,5,-12,9,-21],reverse=True))
print(sorted([36,5,-12,9,-21],key=abs))
print(list(map(lambda x: x * x, [1, 2, 3, 4, 5, 6, 7, 8, 9])))
import functools
def log(func):
@functools.wraps(func)
def wrapper(*args, **kw):
print('call %s():' % func.__name__)
return func(*args,**kw)
return wrapper
def logtext(text):
def decorator(func):
@functools.wraps(func)
def wrapper(*args,**kw):
print('%s %s():' % (text,func.__name__))
return func(*args,**kw)
return wrapper
return decorator
@log
def now():
print('2021--9-01')
@logtext('logtext')
def nowtext():
print('2021--9-01')
print(now())
print(nowtext())
print(int('110011',base=2))
def in2(x,base=2):
return int(x,base)
from email.mime import base
import functools
int2=functools.partial(int,base=2)
print(in2('011110'))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/longing/python-study.git
git@gitee.com:longing/python-study.git
longing
python-study
pythonStudy
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385