1、首先,函数是对象
2、

def fun1(*n):res=mysum(n)print(res)def mysum(n:list):if not n:return 0else:return n[0]+mysum(n[1:])def mys(name:'',degree:int,inc:int)->int:print(name,":",degree,"=>",inc)fun1(12,13,14,15,16,99,88)
fun2=fun1
print(fun1.__name__)
print(fun2.__name__)
mys("张三",12,32)
print(dir(fun2))
print(mysum.__annotations__)
print(mys.__annotations__)
__name__   函数名
dir(fun2) 函数属性名列表
__annotations__ 函数注释
257
fun1
fun1
张三 : 12 => 32
['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
{'n': <class 'list'>}
{'name': '', 'degree': <class 'int'>, 'inc': <class 'int'>, 'return': <class 'int'>}

自定义函数属性runcount

def mys(name:'',degree:int,inc:int)->int:print(name,":",degree,"=>",inc)mys.runcount=0
mys("张三",12,32)
mys.runcount+=1
print(mys.runcount)
print(dir(mys))
fun2=mys
fun2("张三",12,32)
fun2.runcount+=1
print(dir(fun2))
print(fun2.runcount)
张三 : 12 => 32
1
['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'runcount']
张三 : 12 => 32
['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'runcount']
2

python3精要(24)-函数内省、函数注释、函数属性相关推荐

  1. python3精要(19)-全局变量global和工厂函数,lambda,变量作用范围,nonlocal

    一.全局变量global语句: 1.全局变量是位于模块文件的内部顶层的变量名 2.全局变量是在函数内被赋值的话,必须通过global声明 3.全局变量名在函数内部不经营声明也可被引用 二.工厂函数 d ...

  2. Python3进阶--正则表达式、json、logging日志配置、数据库操作、枚举、闭包、匿名函数和高阶函数、time、datetime

    第一章 变量.常用循环体.代码结构.代码练习 第二章 列表.元组等数据结构.字符串驻留机制及字符串格式化操作 第三章 函数.面向对象.文件操作.深浅拷贝.模块.异常及捕获 第四章 项目打包.类和对象高 ...

  3. [原创]Enterprise Architecture V7.5 C++代码生成时,头文件中函数声明没有注释,CPP中函数定义却有注释。...

    这几天一直在用Enterprise Architecture来抽象项目中要用到的一些数据结构和类,然后都做得差不多了之后发现,生成代码的时候.h文件中类成员函数部分没有注释,但是.cpp文件中的函数定 ...

  4. python3 format函数_【Python3 第三日】%和format格式化输出 函数

    格式化输出 print(f'{d}') 会把d代表的意义转化掉,和format差不多 %格式化形式 #这里只说明字典使用 dict1 = {"what": "this y ...

  5. PHPstorm 函数或者方法的注释的时间和用户名,PHPstorm里函数方法的注释是没有动态时间设置的,但是看了PHP file里面有时间日期的注释,而PHP Function Doc Commen

    PHPstorm 函数或者方法的注释的时间和用户名,PHPstorm里函数方法的注释是没有动态时间设置的,但是看了PHP file里面有时间日期的注释,而PHP Function Doc Commen ...

  6. 看看函数名和注释,AI就能自动生成代码,程序员:这不真实,我要失业

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转载自:机器之心  参与:张倩.Racoon X.Jamin 你 ...

  7. erlang精要(19)-以函数作为参数的函数,返回函数的函数(2)

    下面以一个综合例子来整合前一节的内容: 以函数作为参数的函数 返回函数的函数 例子功能是完成求第一个参数列表能全部被第二个参数列表整除的元素. -module(learnerl). -export([ ...

  8. ggplot2 | 注释函数

    本篇推文来介绍图形的注释功能.在基础绘图系统中,注释功能主要由次级函数来实现,如text()函数可以添加文本.mtext()函数添加轴标签.segments()添加短线.arrows()函数添加箭头. ...

  9. 24.请编写一个函数fun,它的功能是:将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。

    24.请编写一个函数fun,它的功能是:将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数). 例如,若输入字符串"-1234",则函数把它转换为整数值- ...

最新文章

  1. 最新版,别的可以不用看了,zabbix 监控 esxi
  2. Spark程序运行常见错误解决方法以及优化
  3. Linux疑难杂症解决方案100篇(五)-SHELL脚本中case语句的多种使用场景
  4. PAT (Basic Level) 1045 快速排序(思维)
  5. Homogeneous Coordinates(齐次坐标)
  6. 提高编程水平的一段必经之路,研读官方文档
  7. Java笔记-java web实现验证码
  8. (NO.00005)iOS实现炸弹人游戏(七):游戏数据的序列化表示
  9. STM32F103:二.(5)控制HC-SR04超声波
  10. [vscode] 禁止 pylance 插件自动添加 import
  11. Tensorflow:模型保存和服务
  12. java url解码_如何从REST WebService 调用中解码路径参数
  13. 概率论与环境数理统计 20210222
  14. app上传到安卓各大市场
  15. centos7.1 修改selinux相关机制后出现开机失败,报错faild to load selinux policy  freezing
  16. spark dataframe 一列分隔多列,一列分隔多行(scala)
  17. F28335第七篇——新建项目之编程演示
  18. JAVA基础语法_1
  19. STM32 BLDC无刷直流电机 HALL霍尔硬件接口 程序
  20. 时间序列预测模型TBATS

热门文章

  1. VMWARE错误-VirtualInfrastructure.Utils.ClientsXml的类型初始值设定项引发异常
  2. 【leetcode】Word Break(python)
  3. Python蜕变-2017-4-23
  4. Linux系统中CPU使用率查询常用的5个命令
  5. ERP 我最看重什么?
  6. 一次MySQL性能优化实战(转)
  7. SNMP学习笔记之SNMPv3的配置和认证以及TroubleShooting
  8. C#开启线程的四种方式
  9. sqlserver的四种分页方式
  10. 沧海一声笑,移动应用的CRASH原因我找到! --记最新款数字化測试“星云測试“的使用攻略...