python(一)初级阶段
1. python安装和环境搭建
windows环境下安装:
官网下载pythona安装包:https://www.python.org/downloads/,选择支持windows版本的。
下载好后,找到刚才下载的文件夹,双击安装包python.exe
- **选择Customize Installation模式安装,勾选add python 3.7 to path, Next;**
- **选择documentation、pip、tcl/tk and IDLE、python test suite, Next;**
- **选择安装路径,安装完成**
- **配置环境变量:计算机-属性-高级系统设置-环境变量-path-编辑-添加刚刚的安装路径;确定;**
- **测试:windows+R :cmd -----输入python**
linux环境下安装:
略,后续补充。
2. python的基础语法
- python 支持脚本时编程和使用pycharm工具编程
- Python标识符由字母、数字、下划线组成
- Python标识符可以包括英文、数字以及下划线,不能以数字开头
- Python中的标识符区分大小写
- Python中以**单下划线开头**的代表不能直接访问的类属性,**需要通过类提供的接口进行访问**,且不能使用Import * 导入
- Python以**双下划线开头**的代表类的私有成员
- Python中以**双下划线开头和结尾**的代表特殊方法的专用标识,例如__init__(),类的构造函数
- Python代码块使用**行和缩进**
3. python的几大变量类型
- Python中变量不需要类型声明
- Python中的五大标准数据类型
**Numbers、String、List、Tuple、Dictionary**
- Numbers(数字类型): int、long、float、complex
- String字符串类型:Str1="2" ,Str2,Str3='2334'
取值:c = Str[0] #2
- List列表类型: list1=[23,'23',2,23.3]
- Tuple元组类型: tuple1=("23",2332,32.4)
特点:
元组中的数据是不允许被更新的;
元组中的数据类型可是不同种类
- Dictionary字典类型: dict={"test1":"za","test2":"ra"}
4. python的条件语句
a=10
if(a>0)
print(a)
elif:
print(0)
else:
print(-1)
5. python的循环语句
index=0
a=(21,"23",1.23,12)
while(a[index]==0)
print(0)
index=index+1
b=["test":"za","test2":"ra","test3":"ta"]
for index in b
print(index)