Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
254
|
7 章 核心內建功能和標準程式庫模組
popleft d
.popleft()
d
移除並回傳第一個(最左邊的)項目。如果
d
是空
的,提出
IndexError
rotate d.rotate(n=1)
d
向右轉動(rotate
n
步(如果
n<0
,就向左轉動)。
namedtuple
namedtuple
是一個工廠函式(factory function),會建置並回傳
tuple
的一
個子類別,其實體的項目可用屬性參考(attribute reference)來存取,也
可以用索引。
namedtuple namedtuple(typename,fieldnames)
typename
是一個字串,它是有效的識別字(以一個字母開頭,後面可以接
著字母、數字與底線,不能是保留字,例如
'class'
),作為
namedtuple
所建置並回傳的新類別之名稱。
fieldnames
是字串所構成的一個序列,它
們是有效的識別字,作為新型別之屬性的名稱,依序列出(為了方便,
fieldnames
也可以是單一個字串,其中的識別字以空格或逗號分隔)。
namedtuple
回傳一個型別:你可以將那個型別繫結至一個名稱,然後用它
來製作以位置或具名引數初始化的不可變實體。在那些實體上呼叫
repr
str
會將它們格式化為具名引數的形式,例如:
point = collections.namedtuple('point', 'x,y,z')
p = point(x=1,y=2,z=3) # 可用具名引數 來建置
x, y, z ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

利用 Python 进行数据分析(原书第2版)

利用 Python 进行数据分析(原书第2版)

Wes McKinney

Publisher Resources

ISBN: 9789864766819