当前位置:网站首页>getattr() function analysis
getattr() function analysis
2022-08-02 03:33:00 【woshicaiji12138】
1Brief
getattr(object, name [, default ])object is an object, and name must be a string; if the value of name is an attribute of the object object, the function outputs the attribute of the object, which is equivalent to object.name.
class Student:def __init__(self,name):self.name = names = Stduent('zhangsan')getattr(s,'name')The output result is zhangsan.
If the value of name is not an attribute of the object object, if the default value is set at this time, the function will output the default value; otherwise, an error will be reported.
class Student:def __init__(self,name):self.name = namegetattr(s,'age',1) #The attribute age does not exist, but a default value is provided, return the default value#will output 12 Application
In general, the above functions are multi-purposed with a certain attribute of object. However, for an object with multiple attributes, the getattr() function can be used when the type of the attribute needs to be called at present.When you can realize which property you need, you can type the name to get the corresponding value.
边栏推荐
- sh: 1: curl: not found
- @DateTimeFormat注解
- 我的两周年创作纪念日
- mysql8.0安装教程与配置(最详细)操作简单
- JSP WebSehll backdoor script
- 2022.7.30 js笔记 运算符和流程控制符、循环
- Daily practice------There are n integers, so that the previous numbers are moved back m positions in order, and the last m numbers become the first m numbers
- getattr()函数解析
- MySQL分页查询的5种方法
- Mysql8创建用户以及赋权操作
猜你喜欢
![[Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)](/img/da/5f6b1ed89cb3fed3cbe6aea840f473.png)
[Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)

脚手架安装

UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the index ing argu

第十一天&shell脚本

磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000

Scaffolding installation

二维数组实战项目--------《三子棋》

磷脂-聚乙二醇-醛基 DSPE-PEG-Aldehyde DSPE-PEG-CHO MW:5000

mysql中如何查看表是否被锁

HCIP-第十一天-MPLS+BGP
随机推荐
浏览器的工作原理(dns域名服务器,tcp握手,ssl/tls安全协议,关键渲染路径,重绘及回流,防抖和节流)
数据库操作作业
DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶供应,MW:5000
活体检测 Adaptive Normalized Representation Learning for GeneralizableFace Anti-Spoofing 阅读笔记
np.isnan()
Brute force visitors
Redis笔记基础篇:6分钟看完Redis的八种数据类型
云服务器安装部署Nacos2.0.4版本
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
DSPE-PEG-DBCO 磷脂-聚乙二醇-二苯并环辛炔 一种线性杂双官能聚乙二醇化试剂
[Remote Control Development Basic Tutorial 3] Crazy Shell Open Source Formation UAV-ADC (Joystick Control)
About cross-domain issues
【深度学习】从LeNet-5识别手写数字入门深度学习
线性代数学习笔记3-1:矩阵与线性变换、常见矩阵(逆矩阵、伴随矩阵、正交矩阵等)
Deveco studio 鸿蒙app访问网络详细过程(js)
@DateTimeFormat注解
DOM destruction and reproduction experiment
@Accessors 注解详解
我的两周年创作纪念日