樹莓派型號:Zero W
樹莓派系統:Raspbian,2018-11-13-raspbian-stretch-lite.img
Python版本:2.7.13、3.5.3
系統安裝完成后,自帶了兩個版本的python:2.7.13、3.5.3,python默認是指python2。pi@raspberrypi:~ $ python --version
pi@raspberrypi:~ $ python3 --version
啟動python
打印一個hello world,然后退出(在 >>> 之后輸入代碼)
- python2
pi@raspberrypi:~ $ python
- python3
pi@raspberrypi:~ $ python3
運行python
上面的例子是直接在python下編程,也可以寫好一個python文件,然后再運行。
用nano編輯器新建一個hello.py文件,輸入 print('hello world!'),保存退出
pi@raspberrypi:~ $ sudo nano hello.py
用python運行hello.py文件,可以看到打印的結果
- python2
pi@raspberrypi:~ $ python hello.py
- python3
pi@raspberrypi:~ $ python3 hello.py