# 開始使用MicroPython

在預設的micro:bit程式設計選項中，第一種是以積木的方式來設計的MakeCode，第二種選擇則是透過Python語言來設計程式的MicroPython，在官網中可以找到這兩種方式的任何一種。使用積木的好處是簡單容易上手，不需要記憶一大堆程式指令，而且在編輯環境中也有模擬器可以馬上看到程式積木的執行結果，但缺點是不容易完成複雜的程式，因為隨便一些功能都會在畫面上出現一大堆積木，很快地就會眼花撩亂了，而且，也不容易複製別人的成果加以修改。因此，當你的程式變得比較大一些的時候，建議可以考慮使用MicroPython來開發。

micro:bit官網的MicroPython進入點如下：

![](/files/-LeKxMuM_bPf04nxXhgN)

Python編輯畫面如下：

![](/files/-LeKxagU3i18su2XWa5W)

在Python的編輯環境中，第一次進入的時候即有一個示範的程式可以讓你執行看看，所有可以執行的指令都在箭頭所指的說明按鈕中，點選help按鈕，有三個項目可以選擇：

![](/files/-LeKxyq15x0gYPQpMyom)

請點選Documentation，就會前往MicroPython for micro:bit的說明文件官網：

![](/files/-LeKyHo3wYLgQ3X8CjVu)

想知道有什麼指令可以使用，或是執行的範例程式，在上面的網站上都可以查詢得到。其實，求助也不一定要進入Python Editor，使用自己的瀏覽器前往以下的網址也是一樣的。

{% embed url="<https://microbit-micropython.readthedocs.io/en/v1.0.1/>" %}

雖然在micro:bit官網提供的Python編輯環境還算是可用，但是在瀏覽器上操作的效率總是比不上在作業系統中執行的專屬應用程式，因此，老師還是建議你前往以下的網址下載好用的Mu Editor：

{% embed url="<https://codewith.mu/>" %}

執行安裝的時候別忘了要把你的micro:bit連接到你的電腦，這樣子的話，它的安裝程式會順便幫你安裝上可以使用REPL的USB驅動程式喔。下面是Mu Editor的執行畫面：

![](/files/-LeKzPQDPfgnblB8qpaE)

編寫好你的程式之後，可以按下「Check」按鈕檢查語法是否正確，按下「Flash」即可把程式寫入到micro:bit上執行喔。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nkust.gitbook.io/micro-bit/shi-shi-yong-micropython.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
