擅长:python、mysql、java
<p>您可以创建自定义<code>namedtuple</code>数据类型:</p>
<pre><code>from collections import namedtuple
# create a new data type (internally it defines a class ContactData):
ContactData = namedtuple("ContactData", ["name", "city", "state"])
# create an object as instance of our new data type
alex = ContactData("Alex", "Taiwan", "Vietnam")
# access our new object
print(alex) # output: ContactData(name='Alex', city='Taiwan', state='Vietnam')
print(alex.city) # output: Taiwan
print(alex[1]) # output: Taiwan
alex[0] = "Alexander" # set new value
print(alex.name) # output: Alexander
</code></pre>