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 .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.14
2 changes: 1 addition & 1 deletion Day01-20/01.初识Python.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 初识Python
## 初识Python

### Python简介

Expand Down
38 changes: 19 additions & 19 deletions Day01-20/04.Python语言中的运算符.md
Original file line number Diff line number Diff line change
@@ -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` | 逻辑运算符 |
| `=`、`+=`、`-=`、`*=`、`/=`、`%=`、`//=`、`**=`、`&=`、`\|=`、`^=`、`>>=`、`<<=` | 赋值运算符 |

> **说明**: 所谓优先级就是在一个运算的表达式中,如果出现了多个运算符,应该先执行什么再执行什么的顺序。编写代码的时候,如果搞不清楚一个表达式中运算符的优先级,可以使用圆括号(小括号)来确保运算的执行顺序。

### 算术运算符

Expand Down
245 changes: 245 additions & 0 deletions Day01-20/Day01-20.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
Empty file added Day01-20/Day01-20.py
Empty file.
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions src/python_100_days/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main() -> None:
print("Hello from python-100-days!")
8 changes: 8 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.