2017-12-23から1日間の記事一覧

MicroPython メモ 10 / format() メソッド

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.67 {} がプレースホルダーとして働く。 ―――――――――――――――――――――― Lua の場合:

MicroPython メモ 9 / ステートマシン / それに意味のないとき

参考: Programming the BBC micro:bit: Getting Started with MicroPython, pp.59-65 from microbit import * state = "A" def handle_A_state(): global state if button_b.is_pressed(): state = "B" display.show(state) def handle_B_state(): global st…

MicroPython メモ 8 / グローバル変数とローカル変数と

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.62 1 行目の変数 a はグローバル変数であり、4 行目の変数 a はローカル変数であるため、全然別の変数であると見なされる。 函数内で global コマンドを使えば、グローバル変数 a…

MicroPython メモ 7 / 辞書

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.53-54 辞書はいわゆる聯想配列のことである (Lua はリストも辞書もテーブルとして一緒くたに扱う)。 辞書は { key : value , key : value , ...... } という形でコンストラクトす…

MicroPython メモ 6 / リスト

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.45-51 リストはいわゆる配列のこと。[ ] で括ってコンストラクトする。インデックスは Lua とは違って普通に 0 から始まる。インデックスの指定は他の言語と同じく [ ] で括る。 …