摘要:
`class BlogPost: def init(self, title, content): self.title = title self.content = content def show(self): print(f"《{self.title}》\n{self.content}") po 阅读全文
posted @ 2026-05-19 18:22
白底纸板
阅读(5)
评论(0)
推荐(0)
摘要:
try: num = int(input("请输入一个整数: ")) result = 100 / num print(f"100/{num}={result}") except ValueError: print("输入不是整数") except ZeroDivisionError: print( 阅读全文
posted @ 2026-05-19 18:22
白底纸板
阅读(6)
评论(0)
推荐(0)
摘要:
`# 写入文件 with open("test.txt", "w") as f: f.write("第一行\n第二行") 读取并打印 with open("test.txt", "r") as f: for line in f: print(line.strip())` 知识点: 打开文件、读取行、 阅读全文
posted @ 2026-05-19 18:22
白底纸板
阅读(8)
评论(0)
推荐(0)
摘要:
`def greet(name, msg="你好"): return f"{msg},{name}" print(greet("园友")) # 你好,园友 print(greet("园友", "早上好")) # 早上好,园友` 知识点: 定义函数、默认参数、return 语句 阅读全文
posted @ 2026-05-19 18:20
白底纸板
阅读(7)
评论(0)
推荐(0)
摘要:
nums = [1, 2, 3, 4] squares = [x*x for x in nums] print(squares) # [1, 4, 9, 16] 知识点: 创建列表、访问元素、列表推导式一行生成平方数 阅读全文
posted @ 2026-05-19 18:20
白底纸板
阅读(8)
评论(0)
推荐(0)
摘要:
`name = "博客园" version = 1.0 is_good = True print(f"欢迎来到 {name} {version},好用吗?{is_good}")` 知识点: 变量命名、整数/浮点数/字符串/布尔值 阅读全文
posted @ 2026-05-19 18:20
白底纸板
阅读(7)
评论(0)
推荐(0)

浙公网安备 33010602011771号