1. 程式人生 > 其它 >Python筆記_8函式之自查函式

Python筆記_8函式之自查函式

前言導讀
自查函式可以幫助我們檢視python所有物件的資訊

一 dir()和help()說明:

#說明:
1 python內建了很多內建函式、類方法屬性及各種模組。
2 當我們想要當我們想要了解某種型別有哪些屬性方法以及每種方法該怎麼使用時,
3 我們可以使用dir()函式和help()函式在python ide互動式模式下獲得我們想要的資訊。

dir():用來查詢一個類或者物件所有屬性,比如:
help():函式幫助我們瞭解模組、型別、物件、方法、屬性的詳細資訊
    詳細資訊包括:類的建立方式、屬性、方法

二 help()檢視功能

1 檢視python所有的關鍵字:help("keywords")
2 檢視python所有的modules:help("modules")
3 檢視python所有的modules中包含指定字串的modules: help("modules yourstr")
4 檢視python中常見的topics: help("topics")
5 檢視python標準庫中的module:import os.path + help("os.path")
6 檢視python內建的型別:help("list")
7 檢視python型別的成員方法:help("str.find") 
8 看查python內建函式:help("open")
9 檢視資料型別  print type (變數名)   
10 檢視python中的關鍵字  import keyword
                      keyword.kwlist

(本章完)

所有資源均有PDF目錄版,如想獲得請掃碼關注右側公眾號自動獲取