「Python」Python 01 基础语法
2018-02-08 10:11
281 查看
① Python 基本数据类型
Number「int、float、bool、complex」
String(字符串)
List(列表)
1.列表中每个元素可变;
2.列表可存储 Python 任何对象;
Tuple(元组)
1.固定版本列表,元组不可修改;
Dictionary(字典)
1.数据必须以键值对形式出现;
2.键(key)不能重复,且不可变,值(Value)可变,可以是任何对象
sets(集合:无序,不重合的任意对象)
② Python 条件控制
age = 30 if age >= 20: print('Young') elif age >= 40: print('Man') else: print('else')
③ Python 循环
○ for 循环:
lists = ['n1', 'n2', 'n3', 'n4'] for i in lists: print(i)
○ While 循环
i = 0 size = 5 while i < size: print('i =', i) i += 1
④ Python 函数
函数通用格式:def 函数名(参数列表): 函数体
实例
def hello(): print('Hello,Python3') hello() # 函数调⽤
⑤ Python 类
类的继承「Python 类可以多继承」⑥ Python 模块
Python 模块理解:Java 语言 包「package」 类似,使用Import语句导入
⑦ Python 输入输出
输出:Print()
读取键盘输入:
input()
⑧ Python 文件
基本格式:file = open(filename, mode)
文件对象方法:
file.read() file.readline() file.readlines() file.close()
读取文件:
file = open('F:/install_notes_cn.txt', 'r') for line in file.readlines(): print(line)
相关文章推荐
- Python_01_基础语法
- Python语法基础01.注释
- 01-Python学习笔记-基础语法
- Python基础语法01
- Python基础 -- 01 Python的基础语法(数据类型、输入输出、运算符、数据类型转换、判断语句、循环语句)
- 01Python基础语法
- week01_python基础语法__01
- Python语法基础_控制流语句_if、while、for
- python系列一:python3基础语法
- 12月28日二周四次【Python基础语法】
- python语法基础-cPickle.dump使用
- Python学习笔记(2):语法基础
- python3的基础语法
- Python学习5-基础语法
- Python入门基础语法之序列、字典、函数、递归
- Python基础--正則表達式基本的语法以及re模块
- Python基础语法学习(字符串)
- Python 基础语法(1)
- python基础语法中所遇到的错误整理
- Python自学笔记系列一——基础语法