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 技術手冊 第三版
Cython
|
765
Cython 運算式
除了 Python 運算式語法,Cython 可以使用一些(但非全部的)C 語法。
要取得變數
var
的位址,就使用
&var
,就像 C 中那樣。然而,要解參考
dereference)一個指標
p
,要用
p[0]
,等效的 C 語法
*p
Cython 中無
效。在 C 中你會使用
p->q
的地方,在 Cython 中就使用
p.q
Null 指標使
Cython 的關鍵字
NULL
。字元常數(char constants)使用語法
c'x'
。轉型
casts)使用角括號(angle brackets),例如 C 中的
(int)somefloat
要寫
<int>somefloat
,此外,只在 C 值上使用轉型,轉成 C 型別,
永不
用在
Python 的值與型別上(遇到 Python 值或型別時,讓 Cython 為你自動進行
型別轉換)。
一個 Cython 範例:最大公因數
Euclid(歐幾里得)用於兩個數字的 GCDGreatest Common Divisor,最
大公因數)演算法以純 Python 實作起來相當簡單:
def gcd(dividend, divisor):
remainder = dividend % divisor
while remainder:
dividend = divisor
divisor = remainder
remainder = dividend % divisor
return divisor
Cython
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