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 技術手冊 第三版
序列運算
|
77
Python
行為就像是對於串列特定切片的指定動作。在表 3-3 中,
L
代表任何串列物
件,
i
代表
L
中任何有效的索引,
s
是任何 iterable,而
x
是任何物件。
3-3 串列物件的方法
方法 說明
非變動式
L .count( x )
回傳
L
中與
x
相等的項目之數量。
L .index( x )
回傳
L
中第一個與
x
相等的項目之索
引,或是在
L
中沒有這種項目時提出一
個例外。
變動式
L .append( x )
將項目
x
附加(append)到
L
的尾端,
等同於
L[len(L):]=[x]
L .extend( s )
iterable
s
的所有項目附加到
L
的尾
端,等同於
L[len(L):]=s
L += s
L.insert(i, x)
將項目
x
插入到
L
中位於索引
i
的項目
的前面,後續的項目(如果有的話)會
「往右移」以空出位置(將
len(L)
一,不會取代任何項目,不會提出例
外,行為等同於
L[i:i]=[x]
)。
L .remove( x )
移除
L
中第一個與
x
相等的項目,或在
L
沒有這種項目時提出一個例外。
L.pop(i=-1)
回傳位於索引
i
的項目之值,並將它從
L
移除;當你省略
i
,移除並回傳的會是
最後一個項目;如果
L
是空的或
i
不是
L
中的有效索引,就會提出一個例外。
L .reverse()
就地反轉(reverse
L
中項目的順序。
L.sort(cmp=cmp, key=None, reverse=False)
就地排序(sort
L
中的項目,僅限於
v2,以傳入作為
cmp
的函式(預設是內
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

測試驅動開發|使用 Python

Harry J.W. Percival

Publisher Resources

ISBN: 9789864766819