From 97ee36971ad52ff7978c6abe960480b8ddad3ed6 Mon Sep 17 00:00:00 2001 From: lkjing2021345 <1908499668@qq.com> Date: Sat, 22 Aug 2026 01:09:21 +0800 Subject: [PATCH] =?UTF-8?q?Add=20Day=5F3:=20=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Day_3/README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Day_3/README.md diff --git a/Day_3/README.md b/Day_3/README.md new file mode 100644 index 0000000..3c1ad90 --- /dev/null +++ b/Day_3/README.md @@ -0,0 +1,64 @@ +# Day_3 · 字符串:和文字打交道 + +> 预计耗时:20~30 分钟 +> 后端天天处理文字(用户名、日志、网页内容)。今天把字符串的基本操作学扎实。 + +## 今日知识点 + +- 字符串拼接:`+`(如 `"你" + "好"`) +- **f-string**(推荐):`f"你好,{name}!"` —— 大括号里直接放变量 +- 常用方法:`len(s)` 长度、`s.upper()` 大写、`s.lower()` 小写、`s.strip()` 去首尾空格、`s.split(" ")` 按空格切分 + +## 先学(教程) + +- 菜鸟教程("字符串"一节,重点看 f-string 和常用方法):https://www.runoob.com/python3/python3-string.html +- B站黑马教程(看讲"字符串"的几集):https://www.bilibili.com/video/BV1qW4y1a7fU/ + +## 任务(后做) + +1. 用 f-string 写自我介绍: + ```python + name = "张三" + age = 18 + city = "青岛" + print(f"我叫{name},今年{age}岁,来自{city}。") + ``` + 把名字换成你自己的,运行确认。 +2. 字符串方法练习,**先猜输出再运行**: + ```python + s = "Hello World" + print(len(s)) # 长度是多少? + print(s.upper()) # 大写 + print(s.lower()) # 小写 + print(s.strip()) # 首尾没空格也能跑,试试 " Hello ".strip() + ``` +3. **进阶(加分)**:`words = "apple banana cherry".split(" ")`, + 打印切出来的列表,再数一数有几个单词(用 `len(words)`)。 + +## 完成标准 + +- [ ] 任务 1 打印出完整自我介绍 +- [ ] 任务 2 四行输出都符合预期 +- [ ] (进阶)能切分字符串并数出单词个数 + +**提交方式**:把 `day3.py` 代码贴在当日工单评论里。 + +## 参考解答(先做再看) + +```python +name = "张三" +age = 18 +city = "青岛" +print(f"我叫{name},今年{age}岁,来自{city}。") + +s = "Hello World" +print(len(s)) # 11(含空格) +print(s.upper()) # HELLO WORLD +print(s.lower()) # hello world +print(" Hi ".strip()) # Hi + +# 进阶 +words = "apple banana cherry".split(" ") +print(words) # ['apple', 'banana', 'cherry'] +print(len(words)) # 3 +```