文章目录
第一天
1.1 应用场景
python:运维领域、数据分析、数据采集(爬虫)
2000年 移动互联网 大数据 云计算
2010年 数据采集(爬虫) 强大的网络库
2016年 人工智能
1.2 环境的安装和配置
1.开发环境
新手时期,建议使用一些记事本工具:sublime、vscode、vim、notepad++、EditPLus、atom
集成开发环境 -- Pycharm工具
2.python下载
官方网站:http://www.python.org
ftp官方下载地址:http://www.python.org/ftp/python
3.运行环境
官方Cpython解释器
http://www.python.org
1.2.1 安装过程
1.点击自定义安装,勾选添加PATH环境变量(系统自动安装,不用手动添加)

2.将下图的所有选项勾选

3.勾选第一个选项,安装位置不建议C盘(路径必须为全英文)

4.等待即可

5.点击disable path length limit,禁用系统的Path长度自动限制,减少很多的麻烦

1.2.2 Python的版本
python2.x 不要用 官方已经放弃维护
python3.x 3.8
安装3.5以上版本
第一个python程序

终端是用于测试的,不建议直接在终端上直接写代码,因为不能保存
window命令:
cd(change directory 改变目录) xxxx路径
在window,怎么完成盘符的跳转 盘符号:
演示:
代码段
print('this is my first python code,hello python~~')
1.通过cd进入python代码的根目录 然后执行代码,注意盘符的跳转,以下是windows系统的CMD界面
C:\Users\Yichen\Desktop>cd D:\Users\Yichen\Desktop\py_code
C:\Users\Yichen\Desktop>D:
D:\Users\Yichen\Desktop\py_code>python firstpythoncode.py
this is my first python code,hello python~~
2.直接通过python执行代码
C:\Users\Yichen>python D:\Users\Yichen\Desktop\py_code\firstpythoncode.py
this is my first python code,hello python~~
3.在代码的根目录下的输入栏输入cmd,直接进入当前目录,即不需要盘符,路径等的手动切换

Microsoft Windows [版本 10.0.18363.836]
(c) 2019 Microsoft Corporation。保留所有权利。
D:\Users\Yichen\Desktop\py_code>
D:\Users\Yichen\Desktop\py_code>python firstpythoncode.py
this is my first python code,hello python~~
3.在代码所处的根目录下鼠标右键,点击在此处打开powershell窗口,进入cmd的最高权限
PS D:\Users\Yichen\Desktop\py_code> python .\firstpythoncode.py
this is my first python code,hello python~~
1.3 编码问题
1、如果使用python2开发代码,一定要更改编码问题,python2不支持中文(1字节),
可在2版本的环境下添加这句话coding:utf-8 使其可以识别中文字符
2、python3中,若Unicode格式是 utf-8 ,则代码也必须是utf-8,python3 Unicode编码(4字节)
unicode是一种规范,utf-8是unicode的一种实现
ANSI编码,对于中文用的是GBK
1.4 注释
1、什么叫做注释
标注的解释
注释非常重要 底层的源码 3:1 注释:代码
2、python中有两种注释
单行注释 # 注释
多行注释 用单行注释去模拟(每行来一个#)
三个引号
注意:必须成对出现 """ 注释的内容 """ '''注释的内容 '''
"""
这是一个多行注释
这是一个多行注释
这是一个多行注释
"""
#这是一行注释
1.5 变量
变量:运行时可以发生变化的量
什么是运行时?
代码从最开始到最后一行执行的过程
为什么使用变量?
方便 便于维护、后期管理优化
1.5.1 变量的定义
# 在java、c、c++这些强数据类型语言中,定义变量必须申明变量的类型
int a = 10;
# python是弱数据语言,在定义使用变量的过程中,不用申明变量的类型;解释器会自动根据值来判断
变量名称 = 变量值 # python的变量定义
1.5.2 变量命名规范
1、变量名称只能有 【大小写字母(大小写敏感)、数字、_】(有效符号) 组成
2、数字不能开头!!!
3、不能以关键字或者保留字作为变量的名称!!
C:\Users\Yichen>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
>>>
4、变量命名尽量有意义。
a.小驼峰法 常见于 c、c++、C#、Java
b.下划线 python推荐写法
c.大驼峰法 类名称
小驼峰:userName
下划线:user_name
大驼峰:UserName
1.6 python的数据类型
1.基本数据类型
数值型(number)
整型 int
浮点数(小数) float
复数(虚数)
布尔类型(bool/Boolean)
真(True)、假(False)
字符串(str/string)
被单引号,或者双引号,三引号也是
注意:三引号在python,不仅是多行注释,也是文档注释,还可以是字符串
2.None 空类型,表示一种不存在的意思
3.引用数据类型(复合数据类型)
list 列表
set 集合
dict 字典
tuple 元组
object …
万物皆对象
1.7 全局函数
print(字符串) # 在终端中输出字符串,标准输出函数
type(变量) # 判断变量的类型
input(“字符串提示”) # 标准输入函数
int(字符串) # 将字符串转换为整数
float(字符串) # 将字符串转换为浮点数
str # 将数字转换为字符串
小试牛刀
要求:完成两个数的加减乘除
#用户的输入
num1 = int(input("please input number1: "))
num2 = int(input("please input number2: "))
print("number1 is " + str(num1))
print("number2 is " + str(num2))
#需求的变量定义,加减乘除
add = num1 + num2
sub = num1 - num2
mul = num1 * num2
div = float(num1/num2)
#输出
print('add is ' + str(add))
print('sub is ' + str(sub))
print('mul is ' + str(mul))
print('div is ' + str(div))
代码执行结果
D:\Users\Yichen\Desktop\py_code>python demo.py
please input number1: 2
please input number2: 2
number1 is 2
number2 is 2
add is 4
sub is 0
mul is 4
div is 1.0
第一天的内容就到此为止~
本文详细介绍Python的安装配置、环境设置及基本语法,包括变量、数据类型、全局函数等,适合Python初学者快速入门。
8805

被折叠的 条评论
为什么被折叠?



