From 5633868fe9492989924db3813cbf5eea393daa71 Mon Sep 17 00:00:00 2001 From: boyang3733 Date: Wed, 9 Sep 2026 18:10:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=9D=E8=AF=86Python?= =?UTF-8?q?=E5=92=8C=E8=BF=90=E7=AE=97=E7=AC=A6=E6=96=87=E6=A1=A3=EF=BC=8C?= =?UTF-8?q?=E5=88=9B=E5=BB=BAJupyter=20Notebook=E5=92=8CPython=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .python-version | 1 + .../01.\345\210\235\350\257\206Python.md" | 2 +- ...04\350\277\220\347\256\227\347\254\246.md" | 38 +-- Day01-20/Day01-20.ipynb | 245 ++++++++++++++++++ Day01-20/Day01-20.py | 0 pyproject.toml | 14 + src/python_100_days/__init__.py | 2 + uv.lock | 8 + 8 files changed, 290 insertions(+), 20 deletions(-) create mode 100644 .python-version create mode 100644 Day01-20/Day01-20.ipynb create mode 100644 Day01-20/Day01-20.py create mode 100644 pyproject.toml create mode 100644 src/python_100_days/__init__.py create mode 100644 uv.lock diff --git a/.python-version b/.python-version new file mode 100644 index 0000000000..6324d401a0 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.14 diff --git "a/Day01-20/01.\345\210\235\350\257\206Python.md" "b/Day01-20/01.\345\210\235\350\257\206Python.md" index 1e4a3b43c0..1377dd793c 100755 --- "a/Day01-20/01.\345\210\235\350\257\206Python.md" +++ "b/Day01-20/01.\345\210\235\350\257\206Python.md" @@ -1,4 +1,4 @@ -## 初识Python +## 初识Python ### Python简介 diff --git "a/Day01-20/04.Python\350\257\255\350\250\200\344\270\255\347\232\204\350\277\220\347\256\227\347\254\246.md" "b/Day01-20/04.Python\350\257\255\350\250\200\344\270\255\347\232\204\350\277\220\347\256\227\347\254\246.md" index 4eb7c02c0f..23c324a6e5 100755 --- "a/Day01-20/04.Python\350\257\255\350\250\200\344\270\255\347\232\204\350\277\220\347\256\227\347\254\246.md" +++ "b/Day01-20/04.Python\350\257\255\350\250\200\344\270\255\347\232\204\350\277\220\347\256\227\347\254\246.md" @@ -1,25 +1,25 @@ -## Python语言中的运算符 +## Python语言中的运算符 Python 语言支持很多种运算符,下面的表格按照运算符的优先级从高到低,对 Python 中的运算符进行了罗列。有了变量和运算符,我们就可以构造各种各样的表达式来解决实际问题。在计算机科学中,**表达式是计算机程序中的句法实体,它由一个或多个常量、变量、函数和运算符组合而成,编程语言可以对其进行解释和计算以得到另一个值**。不理解这句话没有关系,但是一定要知道,不管使用什么样的编程语言,构造表达式都是非常重要的。 -| 运算符 | 描述 | -| ------------------------------------------------------------ | ------------------------------ | -| `[]`、`[:]` | 索引、切片 | -| `**` | 幂 | -| `~`、`+`、`-` | 按位取反、正号、负号 | -| `*`、`/`、`%`、`//` | 乘、除、模、整除 | -| `+`、`-` | 加、减 | -| `>>`、`<<` | 右移、左移 | -| `&` | 按位与 | -| `^`、`|` | 按位异或、按位或 | -| `<=`、`<`、`>`、`>=` | 小于等于、小于、大于、大于等于 | -| `==`、`!=` | 等于、不等于 | -| `is`、`is not` | 身份运算符 | -| `in`、`not in` | 成员运算符 | -| `not`、`or`、`and` | 逻辑运算符 | -| `=`、`+=`、`-=`、`*=`、`/=`、`%=`、`//=`、`**=`、`&=`、`\|=`、`^=`、`>>=`、`<<=` | 赋值运算符 | - ->**说明**: 所谓优先级就是在一个运算的表达式中,如果出现了多个运算符,应该先执行什么再执行什么的顺序。编写代码的时候,如果搞不清楚一个表达式中运算符的优先级,可以使用圆括号(小括号)来确保运算的执行顺序。 +| 运算符 | 描述 | +| --------------------------------------------------------------------------------------------------------- | ------------------------------ | +| `[]`、`[:]` | 索引、切片 | +| `**` | 幂 | +| `~`、`+`、`-` | 按位取反、正号、负号 | +| `*`、`/`、`%`、`//` | 乘、除、模、整除 | +| `+`、`-` | 加、减 | +| `>>`、`<<` | 右移、左移 | +| `&` | 按位与 | +| `^`、` | ` | +| `<=`、`<`、`>`、`>=` | 小于等于、小于、大于、大于等于 | +| `==`、`!=` | 等于、不等于 | +| `is`、`is not` | 身份运算符 | +| `in`、`not in` | 成员运算符 | +| `not`、`or`、`and` | 逻辑运算符 | +| `=`、`+=`、`-=`、`*=`、`/=`、`%=`、`//=`、`**=`、`&=`、`\|=`、`^=`、`>>=`、`<<=` | 赋值运算符 | + +> **说明**: 所谓优先级就是在一个运算的表达式中,如果出现了多个运算符,应该先执行什么再执行什么的顺序。编写代码的时候,如果搞不清楚一个表达式中运算符的优先级,可以使用圆括号(小括号)来确保运算的执行顺序。 ### 算术运算符 diff --git a/Day01-20/Day01-20.ipynb b/Day01-20/Day01-20.ipynb new file mode 100644 index 0000000000..162b80dfa6 --- /dev/null +++ b/Day01-20/Day01-20.ipynb @@ -0,0 +1,245 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "9c7b32cf", + "metadata": {}, + "source": [ + "### Day01" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1172643e", + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Hello, World!\")" + ] + }, + { + "cell_type": "markdown", + "id": "da522f50", + "metadata": {}, + "source": [ + " ### 注释" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cde8a596", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\" \n", + "这是注释\n", + "\"\"\"\n", + "#这也是注释\n", + "print(\"Hello, World!\")" + ] + }, + { + "cell_type": "markdown", + "id": "4a552c1b", + "metadata": {}, + "source": [ + "### 变量和类型" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4ff9d767", + "metadata": {}, + "outputs": [], + "source": [ + "print(0b100) # 二进制整数\n", + "print(0o100) # 八进制整数\n", + "print(100) # 十进制整数\n", + "print(0x100) # 十六进制整数\n", + "print(123.456) # 数学写法\n", + "print(1.23456e2) # 科学计数法" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dcac09e7", + "metadata": {}, + "outputs": [], + "source": [ + "a = 100\n", + "b = 123.45\n", + "c = '123'\n", + "d = '100'\n", + "e = '123.45'\n", + "f = 'hello, world'\n", + "g = True\n", + "print(float(a)) # int类型的100转成float,输出100.0\n", + "print(int(b)) # float类型的123.45转成int,输出123\n", + "print(int(c)) # str类型的'123'转成int,输出123\n", + "print(int(c, base=16)) # str类型的'123'按十六进制转成int,输出291\n", + "print(int(d, base=2)) # str类型的'100'按二进制转成int,输出4\n", + "print(float(e)) # str类型的'123.45'转成float,输出123.45\n", + "print(bool(f)) # str类型的'hello, world'转成bool,输出True\n", + "print(int(g)) # bool类型的True转成int,输出1\n", + "print(chr(a)) # int类型的100转成str,输出'd'\n", + "print(ord('A')) # str类型的'd'转成int,输出100\n", + "print(str(a)) # int类型的100转成str,输出'100'" + ] + }, + { + "cell_type": "markdown", + "id": "4ba70961", + "metadata": {}, + "source": [ + "### 运算符" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0bad36a", + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "radius = float(input('请输入圆的半径:'))\n", + "perimeter = 2 * math.pi * radius\n", + "area = math.pi * radius ** 2\n", + "print(f'周长:{perimeter:.2f},面积:{area:.2f}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5559734", + "metadata": {}, + "outputs": [], + "source": [ + "year = int(input('请输入年份:'))\n", + "is_leap = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)\n", + "print(f'{is_leap}')" + ] + }, + { + "cell_type": "markdown", + "id": "c5fe222d", + "metadata": {}, + "source": [ + "### 嵌套" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "545f1275", + "metadata": {}, + "outputs": [], + "source": [ + "score = float(input('请输入成绩:'))\n", + "if score >= 90:\n", + " grade = 'A'\n", + "elif score >= 80:\n", + " grade = 'B'\n", + "elif score >= 70:\n", + " grade = 'C'\n", + "elif score >= 60:\n", + " grade = 'D'\n", + "else:\n", + " grade = 'E'\n", + "print(f'成绩等级为:{grade}')" + ] + }, + { + "cell_type": "markdown", + "id": "2c1b5e4b", + "metadata": {}, + "source": [ + "### 循环" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "321a1770", + "metadata": {}, + "outputs": [], + "source": [ + "total = 0\n", + "for i in range(1, 101):\n", + " total += i\n", + "print(f'1到100的和为:{total}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "28bfaf5e", + "metadata": {}, + "outputs": [], + "source": [ + "print(sum(range(2,101,2))) # 计算1到100之间所有偶数的和\n", + "print(sum(range(1,101,2))) # 计算1到100之间所有奇数的和" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ea91352", + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(1, 10):\n", + " for j in range(1, i + 1):\n", + " print(f'{j}×{i}={i * j}', end='\\t')\n", + " print()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "e693fa8f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "45和34的最大公约数为:34\n" + ] + } + ], + "source": [ + "x=int(input('x='))\n", + "y=int(input('y='))\n", + "if x%y!=0:\n", + " x,y=y,x%y\n", + "print(f'{x}和{y}的最大公约数为:{y}')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python-100-Days (3.14.x)", + "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.14.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Day01-20/Day01-20.py b/Day01-20/Day01-20.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..676c3d1f91 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[project] +name = "python-100-days" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.14" +dependencies = [] + +[project.scripts] +python-100-days = "python_100_days:main" + +[build-system] +requires = ["uv_build>=0.12.10,<0.13.0"] +build-backend = "uv_build" diff --git a/src/python_100_days/__init__.py b/src/python_100_days/__init__.py new file mode 100644 index 0000000000..6ed53a1b6e --- /dev/null +++ b/src/python_100_days/__init__.py @@ -0,0 +1,2 @@ +def main() -> None: + print("Hello from python-100-days!") diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000000..94f2fff2f3 --- /dev/null +++ b/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 3 +requires-python = ">=3.14" + +[[package]] +name = "python-100-days" +version = "0.1.0" +source = { editable = "." }