python备忘录

发布时间 2023-06-05 09:23:41作者: 寡人正在Coding

Python 基本介绍

整理自菜鸟教程,Python3 教程 | 菜鸟教程 (runoob.com)

查看版本

python -V 或 python --version

   

关键特性

  • 易学习、阅读、维护,有主要商业数据库的接口,有广泛的库可以快速进行开发
  • 可移植,可拓展。可调用C++C的代码,也可嵌入到C++C的代码中
  • GUI

   

应用

  • Youtube、Reddit等网站
  • EVE 等网络游戏
  • Blender 等建模工具

   

环境搭建

Python3 环境搭建 | 菜鸟教程 (runoob.com)

Python VScode 配置 | 菜鸟教程 (runoob.com)

   

基础语法

注释

  

多行注释

  

行与缩进

  

多行语句

  

空行

  

同行显示多条语句

   

  

输入

  

打印

   

  

import

Python3 模块 | 菜鸟教程 (runoob.com)

   

基本数据类型

Python3 基本数据类型 | 菜鸟教程 (runoob.com)

基本使用

   

  

多个变量的赋值

   

  

标准数据类型

  

Number

Python3 数字(Number) | 菜鸟教程 (runoob.com)

Isinstance&type

是某类的实例&类型判定

  

数值运算

Python3 运算符 | 菜鸟教程 (runoob.com)

字符串&截取

   

   

   

Python3 字符串 | 菜鸟教程 (runoob.com)

bool

   

   

  

List

   

   

Python3 列表 | 菜鸟教程 (runoob.com)

Tuple

   

Python3 元组 | 菜鸟教程 (runoob.com)

Set

   

Python3 集合 | 菜鸟教程 (runoob.com)

Dictionary

   

Python3 字典 | 菜鸟教程 (runoob.com)

bytes

   

   

   

   

  

数据转换

  

Python3 数据类型转换 | 菜鸟教程 (runoob.com)

   

数据结构的操作

包含数据结构的增改删查等方法

Python3 数据结构 | 菜鸟教程 (runoob.com)

   

控制语句

Python3 条件控制 | 菜鸟教程 (runoob.com)

Python3 循环语句 | 菜鸟教程 (runoob.com)

if

   

嵌套

   

  

match…case

  

3.10增加的,注意较新版本

while

   

while循环使用else语句

  

for

配合range函数使用

嵌入else(for循环迭代完成执行)

  

continue&break

   

  

pass

   

   

  

   

迭代器

列表推导式

  

字典推导式

   

  

集合推导式

  

元组推导式

  

迭代器

使用for循环

  

类实现迭代器

   

   

  

生成器

   

  

   

函数

函数基本用法

   

   

  

参数的可变/不可变类型

  

参数类型

   

必需参数

   

关键字参数

   

默认参数

   

不定长参数

   

   

  

匿名函数

   

  

强制位置参数

  

   

输入&输出

输出格式化

   

   

   

   

format函数

   

   

打印表格

  

  

读取键盘输入

  

   

文件输入输出

open()方法

  

mode参数

   

  

File 常用函数

   

  

   

面向对象

基本概念

  

基本使用

  

构造

  

类的方法

   

  

继承

  

多继承

  

方法重写

Python 子类继承父类构造函数说明 | 菜鸟教程 (runoob.com)

类的属性和方法

   

  

类的内置方法

  

运算符重载

  

   

错误和异常

异常处理

   

  

抛出异常

  

用户自定义异常

  

预定义的清理

Python with 关键字 | 菜鸟教程 (runoob.com)

断言assert

   

  

   

OS

Python3 OS 文件/目录方法 | 菜鸟教程 (runoob.com)

   

正则表达式

Python3 正则表达式 | 菜鸟教程 (runoob.com)