看板 Python 關於我們 聯絡資訊
請問例如 class Data(): def __init__(self, df): self.df = df print(self.df.columns) 例如進來的變數是 pd.DataFrame 但 python 不用宣告變數 請問如何讓 IDE 知道 self.df 是 DataFrame 型態 只是想說能讓 IDE 按 tab 自動去補完剩下的字 謝謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.134.105.199 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1553346502.A.ACC.html
lemon651: 第一個是你縮排錯了,第二個你可以試試在變數後宣告type 03/24 09:05
sean50301: 我用vscode會有XD ipython也是有這個功能的 03/24 13:57
ScottOAO: type annotation 加上冒號型態 03/25 13:21
ok963963ok: 如果你用pycharm 可以參考我的文章 03/25 16:46
ok963963ok: https://link.medium.com/xCCoJAMalV 03/25 16:46
froce: 沒記錯的話,3.5版之後就可以用type hint 03/26 07:31
froce: 之前你可以用assert (type() is )去做 03/26 07:33
froce: 看錯,以為是單純的判斷類型 03/26 07:36
froce: 不過vs code現在的確可以透過type hint去提示你變數的類型 03/26 07:37
froce: 了 03/26 07:37