0222222/Python-Notes

/Python-Notes/Python基础/类/类和对象.py
# Python-Notes

Python 语言的学习笔记

1 Python基础

1.1 Python基本语法

#### 1.1.1 Python基本语法

• `关键字`:如`if`、`for`、`else`等
• `语句`:如`print`、`input`、`if`等
• `变量`:如`a`、`b`、`c`等
• `表达式`:如`a + b`、`if a > b`等
• `函数`:如`print`、`input`、`if`等

#### 1.1.2 Python语句

• `赋值语句`:如`a = 1`
• `条件语句`:如`if a > b:`
• `循环语句`:如`for i in range(10):`
• `函数语句`:如`def f():`
• `输入输出语句`:如`print`、`input`
• `控制语句`:如`break`、`continue`、`pass`等

#### 1.1.3 Python变量

• `声明`:如`a = 1`
• `赋值`:如`a = 2`
• `引用`:如`a`、`b`、`c`
• `作用域`:如全局作用域、局部作用域、函数作用域等

#### 1.1.4 Python表达式

• `算术运算符`:如`+`、`-`、`*`、`/`、`//`、`%`
• `比较运算符`:如`==`、`!=`、`>`、`<`、`>=`、`<=`
• `逻辑运算符`:如`and`、`or`、`not`
• `成员运算符`:如`in`、`not in`
• `身份运算符`:如`is`、`is not`

#### 1.1.5 Python函数

• `定义`:如`def f():`
• `返回值`:如`return`、`return None`
• `参数`:如`def f(a, b):`
• `返回值类型`:如`int`、`float`、`str`、`list`、`dict`、`None`
• `异常处理`:如`try...except...finally...else...`

1.2 Python数据类型

#### 1.2.1 Python基本数据类型

• `数字`:整数、浮点数、复数
• `字符串`:`str`类型
• `列表`:`list`类型
• `元组`:`tuple`类型
• `集合`:`set`类型
• `字典`:`dict`类型

#### 1.2.2 Python列表

• `创建`:如`list1 = [1, 2, 3]`
• `修改`:如`list1[0] = 100`
• `查找`:如`list1.index(1)`
• `删除`:如`list1.remove(1)`
• `添加`:如`list1.append(1)`
• `操作`:如`list1.pop(0)`
• `切片`:如`list1[0:2]`
• `遍历`:如`for item in list1:`
• `合并`:如`list1 + list2`
• `复制`:如`list1.copy()`
• `复制`:如`list1.extend(list2)`

#### 1.2.3 Python元组

• `创建`:如`tuple1 = (1, 2, 3)`
• `查找`:如`tuple1.index(1)`
• `修改`:如`tuple1[0] = 100`
• `删除`:如`tuple1.remove(1)`
• `添加`:如`tuple1.append(1)`
• `操作`:如`tuple1.pop(0)`
• `切片`:如`tuple1[0:2]`
• `遍历`:如`for item in tuple1:`
• `合并`:如`tuple1 + tuple2`
• `复制`:如`tuple1.copy()`
• `复制`:如`tuple1.extend(tuple2)`

#### 1.2.4 Python字符串

• `创建`:如`s = "hello",s = 'hello'`
• `查找`:如`s.index("hello")`
• `修改`:如`s = s.replace("hello", "world")`
• `删除`:如`s = s.strip()`
• `添加`:如`s = s + "world"`
• `操作`:如`s = s.upper()`
• `遍历`:如`for c in s:`
• `切片`:如`s[0:5]`
• `查找`:如`s.find("hello")`
• `替换`:如`s = s.replace