如何获得普林的头衔

2024-05-15 07:35:00 发布

您现在位置:Python中文网/ 问答频道 /正文

如果给我们这个代码:

from collections import namedtuple
Book = namedtuple('Book', 'title author year price')
favorite = Book('Adventures of Sherlock Holmes',
                'Arthur Conan Doyle', 1892, 21.50)
another = Book('Memoirs of Sherlock Holmes', 
               'Arthur Conan Doyle', 1894, 23.50)
still_another = Book('Return of Sherlock Holmes',
                     'Arthur Conan Doyle', 1905, 25.00)

你怎样才能把书名写在另一本要印刷的书里


Tags: of代码fromimporttitleanothernamedtuplecollections
1条回答
网友
1楼 · 发布于 2024-05-15 07:35:00

你可以做:

print(still_another.title)

namedtuple中的每个值都可以通过其名称访问,在您的情况下,标题可以通过.title访问

相关问题 更多 >