使用 %timeit:正式名稱或直接語法
Python 允許你用「正式名稱」或「直接語法」來建立資料結構。這個練習會帶你看看,使用直接語法建立資料結構如何能加快執行時間。
| data structure | formal name | literal syntax |
|---|---|---|
| list | list() |
[] |
| dictionary | dict() |
{} |
| tuple | tuple() |
() |
本練習屬於課程
撰寫高效的 Python 程式碼
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a list using the formal name
formal_list = ____
print(formal_list)
# Create a list using the literal syntax
literal_list = ____
print(literal_list)