1. Python语言
1.1 Python语言的基本概念
- 吉多 龟叔 一个人发明的语言 他使用C语言时觉得代码太多了,觉得不爽,就想发明一种语言增加效率。于是他1989年开发出Python。
- 同时期的Java语言也在1995年面世了,它是sun公司维护的。
1.2 根据转换的时机不同
- 编译型语言: C语言为代表,xx(源码)>编译>yy(编译后的机器码)
优点是 执行速度快,缺点是 跨平台性比较差。 - 解释性语言: Python语言为代表,xx(源码)>解释器>解释执行
优点 执行速度快 跨平台性比较好
1.3 Python语言特色
- 简单易学
- 自由且开发 pip install xxx
- 开平台及可嵌入性
- “内置电池”,大量的标准库和第三方库
- 社区活跃,贡献者多,互帮互助
- 开源语言,发展动力巨大
1.4 Python应用方向
- 常规软件开发
- 科学计算
- 自动化运维
- 云计算
- WEB开发
- 网络爬虫
- 数据分析
- 人工智能
1.5 Python之禅
输入代码 import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
2. 搭建开发环境
2.1 Python的解释器
- 环境搭建就是安装Python的解释器
- Python的解释器分类:
CPython(官⽅版本) ⽤c语⾔编写的Python解释器
PyPy ⽤Python语⾔编写的Python解释器
JPython ⽤Java编写的Python解释器
2.2搭建Python环境
- 下载安装包,https://www.python.org/
- 安装成功后,win键 + R --> CMD --> 回⻋ --> 输⼊Python
- 命令⾏结构
- Python 3. 7. 3 … —> 版本
- Type “help”,“copyright”…—> 版权声明
- 命令提示符 (在后⾯可以直接输⼊指令)
2.3 pip工具的使用
- pip介绍
Python官⽅的PyPi仓库为我们提供了⼀个统⼀的代码托管仓库,所有的第三⽅库,甚⾄你⾃⼰写的开源模块,都可以发布到这⾥,让全世界的⼈分享下载 。 - pip使用
在命令行下,输⼊pip,回⻋可以看到帮助说明:
- 查看pip版本
- 普通安装 与 指定版本安装 与 卸载 列出所有的包 及信息
- 将已经安装的库列表保存到⽂本⽂件中
pip freeze > D:\桌⾯\install.txt
- 使用wheel文件安装
除了使⽤上⾯的⽅式联⽹进⾏安装外,还可以将安装包也就是wheel格式的⽂件,下载到本地,然后使⽤pip进⾏安装。⽐如我在PYPI上提前下载的pillow库的wheel⽂件,后缀名为whl。
可以使⽤pip install pillow-4.2xxxxxxx.whl的⽅式离线进⾏安装
- 换源安装
⾖瓣 :http://pypi.douban.com/simple/
阿⾥ :http://mirrors.aliyun.com/pypi/simple/
中国科学技术⼤学:http://pypi.mirrors.ustc.edu.cn/simple
清华:https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install SomePackage -i http://pypi.douban.com/simple
2.4 Python的第⼀个程序
- 可以在交互模式实现
- 可以⽤Python⾃带的idle
- 可以⽤⾼级开发⼯具如 : PyCharm
3. PyCharm的安装和配置
3.1 PyCharm的安装
由于笔者安装的专业版本好不容易激活的,在这就不卸载重装了,借用一下老师的图片,感谢老师
如果有32位系统的可以打勾32位的
3.2 PyCharm的简单配置
-
主题修改 File–settings–apperance–theme
-
代码字体修改 File–settings–Editor-Font
-
关闭更新 File–settings—apperance—System Settings —
Updates — Automatically check updates for 取消打钩 -
快捷键修改 File–settings—apperance-- Keymap 选择⾃⼰习惯的
快捷键⽅式 -
⾃动导包 File–settings—apperance–General —Auto Import
打钩 -
进制打开上次的⼯程 File–settings—apperance—System
Settings —Reopen last project startup -
修改新建⽂件⽂件头 File–settings–Editor—Code Style — File
and Code Templates — Python Script#!/usr/bin/env python -*- coding: utf-8 -*- @Time : ${DATE} ${TIME} @Author : Jimth Li @File : ${NAME}.py @Software: ${PRODUCT_NAME}
-
修改字体编码 File–settings–Editor—Code Style — File
Encoding — Project Encoding