【Raspberry Pi入门系列3】PYTHON基础

2016-03-111.5万
AI 快速预览详细 收起
本文介绍了Raspberry Pi平台上使用Python编程的基础知识。首先解释了为什么Python适合Raspberry Pi,包括其丰富的API支持和易用性。接着详细介绍了Python的运行环境设置,包括IDE(如IDLE)和文本编辑器加解释器两种方式。文章还涵盖了常用的表达式、数据类型、函数定义与调用、列表操作以及控制流语句。通过这些内容,读者可以轻松上手Python编程,为Raspberry Pi项目打下坚实的基础。
筒子们我又来啦~~~

我又来分享我第三周的笔记啦~~~
这门课的名字叫The Raspberry Pi Platform and Python Programming for the Raspberry Pi~
详细地址戳这个:
https://www.coursera.org/learn/raspberry-pi-platform/home/week/3

啊我笔记原来用英文记的,懒得转换中文了……将就着看吧…………

这一周讲到了Python
首先为什么PYTHON这么适合为Raspberry Pi编程呢?
这是因为:PYTHON 提供很多的API,其中很多都很适合专门为树莓派编程,尤其是当其作为iOT设备的时候。

首先Python是high-level language,越高级的语言使用起来就越简单~~
convenient:
- no declaration of data types
- no pointers
- OOP(Object-oriented Programming)
but slow compared to C/C++:
- interpreted, not compiled

运行环境
:
1. IDE(Integrated Development Environment) e.g. IDLE
    在Raspbian桌面上打开Menu - Programming - Python
2. Text editor and interpreter
    先去用text editor(sublime等)写一个test.py
    在terminal中输入:
  1. <font size="2" face="微软雅黑">python test.py
  2. </font>
复制代码
    然后就能运行啦。
由于第二种方式能用sudo获取最高权限,因此在某些情况下还是使用第二种方式更合适些。

执行方式:
1. Interactive: Python shell(IDLE/python in terminal)   对应运行环境中的IDE
2. Batch(批处理,比如先用sublime写,然后再运行.py文件)对应运行环境中的text editor和interpreter

下面是一些常用的表达式和数据类型:

Algebraic Expressions: +, - , *, /
Boolean Expressions: <, >, ==, !=……
Boolean Operators: and, or, not
Variables, Assignments(Variable types are not declared)
Strings      e.g. ‘Hello, world’
String Operators
【Raspberry Pi入门系列3】PYTHON基础图1
【Raspberry Pi入门系列3】PYTHON基础图2
Indexing Operator
【Raspberry Pi入门系列3】PYTHON基础图3
Functions
输入:
  1. <font size="2" face="微软雅黑">def test():
  2.     print(‘hehe’)</font>
复制代码
(注意缩进!!!不然很有可能会出错)

使用(call the function):
  1. <font size="2" face="微软雅黑">test()</font>
复制代码
Lists
【Raspberry Pi入门系列3】PYTHON基础图4
List Methods
【Raspberry Pi入门系列3】PYTHON基础图5
可以使用PYTHON运行下面的代码试试:
  1. <font size="2" face="微软雅黑">1st = [1, 2, 3]
  2. lst.append(8)</font>
复制代码
Control Flow
一般就三种:if  /  for  /  while

【Raspberry Pi入门系列3】PYTHON基础图6
【Raspberry Pi入门系列3】PYTHON基础图7


【Raspberry Pi入门系列3】PYTHON基础图8
【Raspberry Pi入门系列3】PYTHON基础图9
以上就是PYTHON概览啦~~~~

筒子们可能会发现编程语言之间其实共同性还是特别多的。所以之前如果学过其他编程语言,比如C/C++/JAVA,大概就学下PYTHON的语法就行啦。

比较详细的PYTHON用法可猛戳下面的链接下载python_tutorial的PDF:
http://pan.baidu.com/s/1hrfu66g

当然还有很多资源可以利用,这里推荐RICE UNIVERSITY(饭大)在COURSERA上的PYTHON专项课程
https://www.coursera.org/learn/interactive-python-1/home/welcome

Screen Shot 2016-03-11 at 2.39.35 AM.png (74.17 KB, 下载次数: 3896)

Raspberry Pi入门系列3 · PYTHON基础_image_3.webp

创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(4)
dsweiliang
dsweiliang
来~
iooops
iooops
作者
回复dsweiliang
评论内容
iooops
iooops
作者
地板
占走!!!
iooops
iooops
作者
板凳哈哈哈哈哈哈!!!!!
iooops
iooops
作者
沙发是我的~~~~!!!
- 没有更多了 -