def f(a=1, b=2, c=3):

print(locals())#在函数内获取

 

#使用inspect模块,简单方便

python2.7:

import inspectinspect.getargspec(f)

python3:

https://docs.python.org/3/library/inspect.html

 

inspect.Signature(f)

 

#使用f的内置方法#获取默认值,如果参数名没有默认值则不在其中:

print(f.__defaults__) #使用__code__

print(f.__code__.co_argcount)#总参数个数

print(f.__code__.co_varnames) # 总参数列表tuple

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-14
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
相关资源
相似解决方案