[問題] python3 物件問題

看板Python作者 (splasky)時間9年前 (2016/09/21 20:54), 9年前編輯推噓7(709)
留言16則, 7人參與, 最新討論串1/1
大家好 小弟最近正在閱讀 python程式的原始碼 發現沒有遇過的規則 Q1:def __init__(self, data: bytes): 請問 data:bytes這是表達什麼意思? Q2: def __repr__(self) -> str: 為什麼一個func可以透過指標(? 指向一個str? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 163.17.132.135 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1474462446.A.029.html


09/21 21:10, , 2F

09/21 21:11, , 3F
應該是type hints?
09/21 21:11, 3F

09/21 21:12, , 4F
A1: data的型態是bytes
09/21 21:12, 4F

09/21 21:13, , 5F
A2: 這個func的return值是str
09/21 21:13, 5F
原來是python3的規則 謝謝回覆

, , 6F
cython?
09/21 21:13 ※ 編輯: splasky (1.170.120.1), 09/21/2016 21:53:44 ※ 編輯: splasky (1.170.120.1), 09/21/2016 21:54:16

09/21 22:00, , 7F
A2: PEP484的簡單介紹: (基本上對function沒影響)
09/21 22:00, 7F

09/21 22:00, , 9F
#function-annotations
09/21 22:00, 9F

09/21 23:18, , 10F
還以為能做pattern matching @@
09/21 23:18, 10F

09/23 11:04, , 11F
其實我很好奇的事情是以後cython是否可以用python3指定的
09/23 11:04, 11F

09/23 11:05, , 12F
type直接編譯,而不必在前面再加上一次type。
09/23 11:05, 12F

09/25 10:30, , 13F
就我對python.h裡面的pyObject理解 c階段改成指定type
09/25 10:30, 13F

09/25 10:31, , 14F
是不太可能的吧
09/25 10:31, 14F

09/26 09:17, , 15F
印象中聽過使用type hint並不會提高效率XD
09/26 09:17, 15F

10/01 17:24, , 16F
對 ide 來說應該會有幫助
10/01 17:24, 16F
文章代碼(AID): #1NueBk0f (Python)
文章代碼(AID): #1NueBk0f (Python)