asp调试器 Python基础
发布时间:2022-09-24 14:41:48 所属栏目:Asp教程 来源:
导读: 内建函数:
在py中输入dir( _builtins _)可以看到py解释器默认加载的属性和函数,这些函数称为内建函数,这些函数因为在编程中使用较多,因从py解释器使用c语言实现了这些函数,启动解释器时默认加载。
在py中输入dir( _builtins _)可以看到py解释器默认加载的属性和函数,这些函数称为内建函数,这些函数因为在编程中使用较多,因从py解释器使用c语言实现了这些函数,启动解释器时默认加载。
|
内建函数: 在py中输入dir( _builtins _)可以看到py解释器默认加载的属性和函数,这些函数称为内建函数,这些函数因为在编程中使用较多,因从py解释器使用c语言实现了这些函数,启动解释器时默认加载。 常用内建函数 a=map(lambda x:x*x,(1,2,3)) b=map(lambda x,y:x+y,(1,2,3),[1,2,3]) print(next(a)) print(next(b)) #返回0代表false,1代表true。留下返回true的 filter(lambda x:x%2,(1,2,3,4)) def fun(x): return x%2 b=filter(fun,(1,2,3,4)) print(next(b)) %导入模块 In [1]: from functools import reduce In [2]: reduce(lambda x,y:x+y,(1,2,3,4)) Out[2]: 10 %先将列表中加完,在于后面继续相加 In [3]: reduce(lambda x,y:x+y,(1,2,3,4),5) Out[3]: 15 %如果是字符串,则进行拼接 In [4]: reduce(lambda x,y:x+y,('a','b'),'c') Out[4]: 'cab' #整数和字符串不可混用 In [5]: reduce(lambda x,y:x+y,(1,2,3,4),'c') --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in ----> 1 reduce(lambda x,y:x+y,(1,2,3,4),'c') in (x, y) ----> 1 reduce(lambda x,y:x+y,(1,2,3,4),'c') TypeError: Can't convert 'int' object to str implicitly partial函数(偏函数) 把一个函数的某些参数设置默认值,返回一个新的函数,调用这个函数会更简单。如果没有更改asp调试器,则调用函数就会使用默认值,如果更改了,则会使用更改值 import functools def fun(*args,**kwargs): print(args) print(kwargs) p1=functools.partial(fun,1,2,3) p1() p1(4,5,6) p1(a='py',b='java') print('..........') p2=functools.partial(fun,a='py') p2() p2(4,5,6) p2(a='cpp',b='java') ''' ''' (1, 2, 3) {} (1, 2, 3, 4, 5, 6) {} (1, 2, 3) {'a': 'py', 'b': 'java'} .......... () {'a': 'py'} (4, 5, 6) {'a': 'py'} () {'a': 'cpp', 'b': 'java'} wraps函数 import functools def note(func): @functools.wraps(func) def wrapper(): "inner" print('wrapper') return func() return wrapper @note def test(): "test" print('test') test() print(test.__doc__) pdb调试 逻辑错误才需要使用调试器 常用命令 asp.net mvc 调试源码_asp调试器_asp怎么调试 执行时调试 python -m pdb py文件 C:\Users\lenovo>python -m pdb E:/python/data/test.py > e:\python\data\test.py(1)() -> import functools (Pdb) l 1 -> import functools 2 def note(func): 3 @functools.wraps(func) 4 def wrapper(): 5 "inner" 6 print('wrapper') 7 return func() 8 return wrapper 9 @note 10 def test(): 11 "test" (Pdb) b (Pdb) c wrapper test test The program finished and will be restarted > e:\python\data\test.py(1)() -> import functools (Pdb) s > e:\python\data\test.py(2)() -> def note(func): (Pdb) n > e:\python\data\test.py(9)() -> @note (Pdb) n > e:\python\data\test.py(13)() -> test() (Pdb) 交互式调试 import pdb pdb.run() 程序中埋点 import pdb pdb.set_trace() (编辑:应用网_扬州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |


浙公网安备 33038102330458号