tensorflow学习——collections.namedtuple函数
来源:互联网 发布:linux中usermod 编辑:程序博客网 时间:2024/06/06 16:57
from collections import namedtuple# 定义一个namedtuple类型User,并包含name,sex和age属性。#User = namedtuple('User', ['name', 'sex', 'age'])User = namedtuple('User', 'name, sex, age')# 创建一个User对象user = User(name='kongxx', sex='male', age=21)# 也可以通过一个list来创建一个User对象,这里注意需要使用"_make"方法#user = User._make(['kongxx', 'male', 21])print(user)# User(name='user1', sex='male', age=21)# 获取用户的属性print (user.name)print (user.sex)print (user.age)# 修改对象属性,注意要使用"_replace"方法user = user._replace(age=22)print (user)# User(name='user1', sex='male', age=21)# 将User对象转换成字典,注意要使用"_asdict"print (user._asdict())# OrderedDict([('name', 'kongxx'), ('sex', 'male'), ('age', 22)])
转载自此博客
阅读全文
1 0
- tensorflow学习——collections.namedtuple函数
- Collections -- namedtuple
- python学习——namedtuple方法
- hackerrank Collections.namedtuple()
- Python学习(十八)——list tuple namedtuple
- Python HackerRank|Collections.namedtuple(from collections import namedtuple)
- 命名元组 collections.namedtuple
- collections模块里的:namedtuple
- python from collections import namedtuple
- 关于Python3的collections.namedtuple和functools.namedtuple的探讨
- underscore学习笔记—集合函数/collections(一)
- underscore学习笔记—集合函数/collections(二)
- python模块collections中namedtuple()的理解
- Python的collections模块及namedtuple详解
- 自定义命名的元组collections.namedtuple
- python模块collections中namedtuple()的理解
- python学习——collections
- namedtuple
- [C++] VS中出现未将对象引用设置到对象的实例
- HDOJ 连连看 (DFS (TLE))
- Swift中值类型和引用类型
- 奇货商城重构——webpack自动化工程
- 记一次RedHat中文乱码,中文语言包安装实践
- tensorflow学习——collections.namedtuple函数
- [C++] 继承与同名成员变量
- [C++] 零散知识点
- 银行卡识别OCR开发流程
- Clion this file does not belong to any project target问题解决方案
- select源码剖析
- javascript学习笔记之BOM和DOM详解
- [C++] 前置++和后置++的区别
- unity 通过代码查找一个文件夹下的所有文件