Python:定义特定对象类型的列表 [英] Python : define a list of a specific type of object

查看:789
本文介绍了Python:定义特定对象类型的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从列表中继承以产生myList类,该类仅接受一种特定类型的对象(例如ints). 我相信装饰工可以做到这一点.

I would like to inherit from a list to produce the myList class, that only accepts one specific type of object (say ints). I am sure decorators can do that elegantly.

推荐答案

使用 arrays ?

此模块定义对象类型 可以紧凑地表示一个数组 基本值:字符,整数, 浮点数字.数组是 序列类型,表现非常好 类似于列表,除了 存储在其中的对象受到约束. 类型是在对象上指定的 使用类型代码的创建时间, 这是一个字符.这 定义了以下类型代码:

This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers. Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained. The type is specified at object creation time by using a type code, which is a single character. The following type codes are defined:

这篇关于Python:定义特定对象类型的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆