您的位置:首页 > 编程语言 > Python开发

「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