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 技術手冊 第三版
函式
|
101
Python
「僅限關鍵字」參數(僅限 v3
只在 v3 中,一個
def
述句也可以選擇性地讓你指定,在你呼叫函式的時
候,如果有出現的話,
必須
對應到
identifier=expression
這種形式的具
名引數(參閱後面「引數的種類」)的參數。這些參數叫做(令人困惑
地,因為它們與關鍵字沒有任何關係)
僅限關鍵字參數
keyword-only
parameters
。如果這些參數有出現,它們必須出現在
*args
(如果有的
話)之後,並在
**kwargs
(如果有的話)之前。
一個僅限關鍵字參數可以在參數列中被指定為一個簡單的識別字(在這
種情況下,呼叫函式的時候,就一定要傳入其對應的具名引數),或是
identifier=default
這種形式(在這種情況下,它就是選擇性的,呼叫函式
時可以不傳入其對應的引數,但如果你有傳入,你
必須
將它作為具名引數
傳入,而非位置引數)。每個不同的僅限關鍵字參數都可以使用上面任一
種形式。簡單的識別字,如果有出現的話,比較常見且易讀的做法是把它
們放在僅限關鍵字參數規格(keyword-only parameter specifications)的開
頭,而
identifier=default
的形式,如果有的話,就跟在它們後面,雖然
這不是此語言所要求的。
所有的僅限關鍵字參數規格都放在特殊形式
*args
後面
,如果後者有出
現的話。如果那個特殊形式沒有出現,那麼僅限關鍵字參數規格序列的開
頭必須是一個 null 參數,單純由一個
*
(星號)構成,而且沒有對應的引 ...
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