12267浏览
查看: 12267|回复: 5

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

[复制链接]
筒子们我又来啦~~~

我又来分享我第三周的笔记啦~~~
这门课的名字叫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

iooops  中级技匠
 楼主|

发表于 2016-3-11 17:37:47

沙发是我的~~~~!!!
回复

使用道具 举报

iooops  中级技匠
 楼主|

发表于 2016-3-11 17:37:58

板凳哈哈哈哈哈哈!!!!!
回复

使用道具 举报

iooops  中级技匠
 楼主|

发表于 2016-3-11 17:38:22

地板
占走!!!
回复

使用道具 举报

dsweiliang  初级技神

发表于 2016-3-12 08:17:26

来~
回复

使用道具 举报

iooops  中级技匠
 楼主|

发表于 2016-3-12 13:04:05

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail