作者是一位从事软件开发三年的普通程序员, 一直以来所使用的计算机逻辑语言是 RPGLE, 脚本语言 CLLE, 数据库 DB2. 小众语言就业面窄, 面对最近越来越火的 Python 也希望自己能跟上时代的步伐.
-- 之后的文章更新都是围绕着 Python 从 0 开始学习到.... 一直坚持下去
-- 本专题学习阅读的材料有《廖雪峰官网 Python 教程》《笨办法学 Python3》
-- 欢迎在评论区讨论留言
1. Python3 安装
Python3 的安装还是比较简便的, 打开官网 https://www.python.org/, 直接点击下方 Download Python3.7.3, 下载好以后 打开安装包直接安装即可, Mac 环境下会自动配置环境变量.
download.PNG
2. Python3 的第一次尝试
安装完成之后 Python3 的环境就算搭建好了. 接下来在 Terminal 中, 做一些简单尝试.
- FANGQIdeMacBook-Pro:~ fangqi$ python3
- Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
- [Clang 6.0 (clang-600.0.57)] on darwin
- Type "help", "copyright", "credits" or "license" for more information.
- >>> print("Hello World!")
- Hello World!
- >>> print(1)
- 1
- >>> print(True)
- True
第一个程序当然是 Hello world. 在 python3 中直接使用 print() 输出就好.
3. 如何使用编辑器进行多行 Python 代码的编写
编辑器根据个人喜好选取一款适合自己的就好.
第一个多行 python 代码. PNG
运行结果如下:
- FANGQIdeMacBook-Pro:PythonStudy fangqi$ python3 ex1.py
- Hello World!
- Hello Again!
- I like typing this.
- This is fun.
- Yay! Printing.
- I'd much rather you'not'.
- I "said" do not touch this.
在 python 中行首有 #代表注释行.
如果需要多行注释在每行前加 #
4. python 中的数字和计算
Python 中的基本数据类型有:
整数
浮点数
布尔值
字符串
空值 None(不能理解为 0)
变量
常量
数据和简单的数学计算. PNG
- FANGQIdeMacBook-Pro:PythonStudy fangqi$ python3 ex2.py
- I will not count my chickens:
- Hens 30.0
- Roosters 97
- Noew I will count the eggs:
- 6.75
- Is it true 3+2<5-7?
- False
- What is 3+2? 5
- What is 5-7? -2
- Oh, that's why it's False.
- How about some more.
- Is it greater> True
- Is it greater or equal? True
- Is it Less or equal? False
来源: http://www.jianshu.com/p/82adb1a39cd1