《0021》第二章 Python编程:Python简介与安装及Python基础语法
1、安装必备软件
(1)Python解释器、(2)Pycharm工具、(3)Selenium安装、(4)谷歌驱动安装
2、Python解释器
a.官方下载地址:https://www.python.org/

b.勾选配置细节:记得勾选Add Python 3.8 to PATH(环境配置)若忘记勾选,则将python解释器安装的C:\Python\Python38\Scripts路径 高级系统设置>环境变量>系统变量>Path目录
c.默认选择自定义安装:Customize installation
d.安装路径:C:\Python\Python38(路径可修改)
e.验证安装:打开cmd 输入python
3、Pycharm工具
a.安装类型:PyCharm工具:Professional(专业版收费)、Community(社区版免费)
参考链接安装指引说明:https://blog.csdn.net/qq_44218507/article/details/131698467 https://www.jetbrains.com/
b.安装事项:(1)安装路径:C:\PyCharm CommunityEdition 2020.3.3(路径可修改)
(2)Installation Option:四个勾选入口全部勾选
c.设置pycharm:
(1)改成到本地环境:New Project>location(存放位置,可修改)
New Project>虚拟环境(安装了第三方库,重新创建项目时,还需要安装第三方库)
New Project>本地环境(安装了第三方库,重新创建项目时,不需要安装第三方库)
强烈推荐选择本地环境(Python Interpreter),需要选择Python的解释器:python.exe
(2)改变外观:file>settings>Appearance & Behavior>Theme>Darcula
(3)背景图片:file>settings>Appearance & Behavior>UI Option>Background Image
(4)安装第三方库:file>settings>项目名>Python Interpreter(解释器)>第三方库列表
(5)备注信息:file>settings>Editor>File and code Templates>Python Script>模版(如下)
# -*- coding:utf-8 -*-
#@Time : ${DATE} ${TIME}
#@Author: 千纸鹤
#@File : ${NAME}.py
4、Selenium安装
a.安装方法:打开cmd,输入pip install selenium
b.验证安装:打开cmd,输入pip list(出现selenium的版本)
5、谷歌驱动安装
a.版本映射:chrome的版本和ChromeDriver版本对应表(https://www.cnblogs.com/zwh-py/articles/9890699.html)
b.谷歌驱动:chromedriver需要放在python安装目录下
第一步:ChromeDriver谷歌驱动最新版安118/119/120
https://blog.csdn.net/m0_57382185/article/details/134007615
https://googlechromelabs.github.io/chrome-for-testing/
环境配置
把第二步下载的压缩包进行解压,将解压的chromedriver.exe 放到Python 的 Scripts 目录下。
C:\Users\Admin\AppData\Local\Programs\Python\Python312\Scripts\
c.chrome 关闭自动更新:https://blog.csdn.net/weixin_56175092/article/details/132305142
https://jingyan.baidu.com/article/f3ad7d0f51c6bf09c3345bb0.html(cmd运行msconfig~服务~隐藏~全部禁用)
1、服务中禁用 Google 更新:Google 更新服务 (gupdate)、Google 更新服务 (gupdatem))
2、删除 C:\Program Files (x86)\Google\Update 目录中的所有内容
3、右键点击 Update 文件夹,点击“属性”~“安全”选项卡,System 完全控制权设置为拒绝
6、python开门见山知识
1、print()作用:print()是python中的一个函数 作用:是把括号中的内容显示在控制台
2、注释规则形式:
# 是给代码起到备注的作用,不会运行
# 单行注释: 单行注释(快捷ctrl+/)
# 多行注释:''' 三个引号代表多行注释,可以换行,不会被执行'''
3、变量作用格式:作用是用来存储数据,格式:变量名=值 =赋值 x=3 print(x)、g='a' print(g)
4、导入模块的三种方式
第一种:
import 模块名(包名+类名)
使用方法:模块名.函数名()
import class02.demo2
class02.demo2.test_01()
class02.demo2.test_02()
第二种:
from 模块名(包名+类名) import 函数名,函数名
使用方法:函数名()
from class02.demo2 import test_01 快捷键:alt+enter 自动导包
test_01()
第三种:
from 模块名(包名+类名) import *
使用方法:函数名()
from class02.demo2 import *
test_01()
test_02()
5、数据类型
可变数据类型:字典dict 列表list 集合set
不可变数据类型:数字number 字符串string 元组tuple
数据类型的转换(tuple list):
元组转为列表:tup10=(1,'er') print(list(tup10),type(list(tup10)))
列表转为元组:list8=[1,'2'] print(tuple(list8),type(tuple(list8)))
浙公网安备 33010602011771号