百花谷博客百花谷博客百花谷博客

微信关注,获取更多

所有文章第2页

原创资料

跟着AI学Python 第7课:文件读写

# 第7课:文件读写 —— 让数据"活"起来 # 1.写入文件(w模式:覆盖写入) file = open("test.txt", "w", encoding="utf-8") file.write("第一行:Hello Python!\n") file.write("第二行:文件读写真有趣\n") file.close() # 写完必须关闭,否则内容可能丢...
赞 (0)阅读(281)评论(0)
原创资料

跟着AI学Python 第7课:文件读写

# 第7课:文件读写 —— 让数据"活"起来 # 1.写入文件(w模式:覆盖写入) file = open("test.txt", "w", encoding="utf-8") file.write("第一行:Hello Python!\n") file.write("第二行:文件读写真有趣\n") file.close() # 写完必须关闭,否则内容可能丢...
赞 (0)阅读(263)评论(0)
原创资料

跟着AI学Python 常用快捷功能

VS Code 的自动补全确实很好用,掌握几个窍门能快很多: 1. 输入前几个字母就按 Tab 比如输入 pri,VS Code 会提示 print,按 Tab 键就直接补全,不用打完整个单词。 2. 善用回车选择提示 弹出提示列表后,用上下方向键选中要用的,按 Tab 或 回车 确认。 3. f-string 快捷输入 输入 f 然后引号,再输入变量名花括...
赞 (0)阅读(290)评论(0)
原创资料

跟着AI学Python 核心语法

# 1. 列表创建和取值 fruits = ["苹果", "香蕉", "橘子"] fruits[0] # 取第一个 fruits[-1] # 取最后一个 # 2. 列表增删 fruits.append("西瓜") # 末尾添加 fruits.remove("香蕉") # 删除指定元素 len(fruits) # 长度 # 3. 列表遍历 for fruit ...
赞 (0)阅读(225)评论(0)
原创资料

跟着AI学Python 第5课:函数

# === 函数 === # 1. 定义和调用函数 def say_hello(): print("你好,火鸟!") say_hello() # 调用函数 say_hello() # 可以反复调用 print() # 2. 带参数的函数 def greet(name): print(f"你好,{name}!") greet("小明") greet("小红")...
赞 (0)阅读(231)评论(0)
原创资料

跟着AI学Python 第4课:列表与字典

# === 列表与字典 === # 1. 列表(list):按顺序存放一组数据 print("--- 列表 ---") fruits = ["苹果", "香蕉", "橘子", "葡萄"] print(fruits) # 打印整个列表 print(fruits[0]) # 取第一个元素(索引从0开始) print(fruits[2]) # 取第三个 print...
赞 (0)阅读(211)评论(0)
原创资料

跟着AI学Python 第3课:循环

# === 循环 === # 1. for 循环:已知次数的重复 print("--- for 循环 ---") for i in range(5): # i 依次取 0,1,2,3,4 print(f"第 {i} 次循环") print() for i in range(1, 6): # 从1到5 print(f"第 {i} 次循环") print() f...
赞 (0)阅读(242)评论(0)
原创资料

跟着AI学Python 第2课:条件判断

# === 条件判断 === # 1. 基本的 if / else age = 18 if age >= 18: print("你已成年,可以考驾照了") else: print("你还未成年,再等等哦") print() # 2. 多条件判断:if / elif / else score = 85 if score >= 90: print("...
赞 (0)阅读(217)评论(0)