Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions new-test-20251106.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1232
169 changes: 169 additions & 0 deletions 学习笔记/Pyhton常用模块及函数.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"time 模块\n",
"print()\n",
"str()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### print()函数\n",
"```python\n",
"print('a','b','c') # 输出a b c,因为print参数sep默认为空格' '\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 静态对象\n",
"静态对象一般指程序运行期间不会发生改变的对象,或者不需要实例化就可以直接使用的对象。包括:\n",
"- 模块:导入后可以直接使用的对象。\n",
"- 类的静态成员:无需实例化类即可访问的属性或方法。\n",
"- 不可变对象:值在创建后不会改变的对象。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 数学函数\n",
"| 函数 | 返回值 (描述) | 注意事项 |\n",
"|------|---------------|----------|\n",
"| abs(x) | 返回数字的绝对值,如 `abs(-10)` 返回 `10` | 内置函数,复数则返回其大小 |\n",
"| fabs(x) | 以浮点数形式返回数字的绝对值,如 `math.fabs(-10)` 返回 `10.0` | |\n",
"| ceil(x) | 返回数字的上入整数,如 `math.ceil(4.1)` 返回 `5` | `math.ceil(-4.1)` 返回 `-4` |\n",
"| floor(x) | 返回数字的下舍整数,如 `math.floor(4.9)` 返回 `4` | |\n",
"| exp(x) | 返回 e 的 x 次幂,如 `math.exp(1)` 返回 `2.718281828459045` | |\n",
"| log(x) | 如 `math.log(math.e)` 返回 `1.0`,`math.log(100,10)` 返回 `2.0` | |\n",
"| sqrt(x) | 返回数字 x 的平方根,如 `math.sqrt(100)` 返回 `10.0` | |\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 随机数函数\n",
"| round(x [,n]) | 返回浮点数 x 的四舍五入值,如给出 n 值,则代表舍入到小数点后的位数。|不适合精度要求高的情况;round(2.675,2)会返回2.67,“四舍六入”|\n",
"| sqrt(x) | 返回数字 x 的平方根。|math.sqrt(100)返回10.0|"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 随机数函数\n",
"随机数可以用于数学,游戏,安全等领域中,还经常被嵌入到算法中,用以提高算法效率,并提高程序的安全性。\n",
"需要先导入random模块\n",
"| 函数 | 描述 |注意事项|\n",
"|---------------|-------------|--------|\n",
"| `choice(seq)` | 从序列的元素中随机挑选一个元素,比如 `random.choice(range(10))`,从 0 到 9 中随机挑选一个整数。|seq可以是列表、元组或者字符串|\n",
"| `randrange([start,] stop [,step])` | 从指定范围内,按指定基数递增的集合中获取一个随机数,基数默认值为 1。||\n",
"| `random()` | 随机生成下一个实数,它在 `[0,1)` 范围内。 ||\n",
"| `seed([x])` | 改变随机数生成器的种子 `seed`。如果你不了解其原理,你不必特别去设定 `seed`,Python 会帮你选择 `seed`。 ||\n",
"| `shuffle(lst)`| 将序列的所有元素随机排序。|random.shuffle ()返回值是None|\n",
"| `uniform(x, y)` | 随机生成下一个实数,它在 `[x, y]` 范围内。|返回浮点数,闭区间|\n",
"\n",
"range()返回的是一个range对象,不是一个具体的列表或者元组。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 三角函数\n",
"\n",
"| 函数 | 描述 |\n",
"|---------------|--------------------------|\n",
"| `acos(x)` | 返回 `x` 的反余弦弧度值。 |\n",
"| `asin(x)` | 返回 `x` 的反正弦弧度值。 |\n",
"| `atan(x)` | 返回 `x` 的反正切弧度值。 |\n",
"| `atan2(y, x)` | 返回给定的 `x` 和 `y` 坐标值的反正切值。 |\n",
"| `cos(x)` | 返回 `x` 弧度的余弦值。 |\n",
"| `hypot(x, y)` | 返回欧几里德范数 `sqrt(x*x + y*y)`。 |\n",
"| `sin(x)` | 返回 `x` 弧度的正弦值。 |\n",
"| `tan(x)` | 返回 `x` 弧度的正切值。 |\n",
"| `degrees(x)` | 将弧度转换为角度,如 `degrees(math.pi/2)` 返回 `90.0`。 |\n",
"| `radians(x)` | 将角度转换为弧度。 |\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## operator模块"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.661846320052351\n"
]
}
],
"source": [
"import random\n",
"\n",
"print(random.uniform(2,3))\n"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.661846320052351\n"
]
}
],
"source": [
"import random\n",
"\n",
"print(random.uniform(2,3))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading