树莓派上的第一个Python程序

>> [目录] 数据远程采集 Step by Step


树莓派型号: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

image

pi@raspberrypi:~ $ python3 --version

image


启动python


打印一个hello world,然后退出(在 >>> 之后输入代码)

  • python2

pi@raspberrypi:~ $ python

image

  • python3

pi@raspberrypi:~ $ python3

image


运行python


上面的例子是直接在python下编程,也可以写好一个python文件,然后再运行。

用nano编辑器新建一个hello.py文件,输入 print('hello world!'),保存退出

pi@raspberrypi:~ $ sudo nano hello.py

image

用python运行hello.py文件,可以看到打印的结果

  • python2

pi@raspberrypi:~ $ python hello.py

image

  • python3

pi@raspberrypi:~ $ python3 hello.py

image


原文地址:https://www.cnblogs.com/hotwater99/p/12737656.html