Modify print demo

This commit is contained in:
Henry Lin 2025-08-25 15:46:44 +08:00
parent e9e46db307
commit f5b0f21bac
3 changed files with 26 additions and 9 deletions

1
0001/output.txt Normal file
View File

@ -0,0 +1 @@
Hello

1
0001/output_2.txt Normal file
View File

@ -0,0 +1 @@
Save to output_2.txt

View File

@ -1,12 +1,27 @@
# 输出字符串 # 输出一个字符串
print("Hello World") print("Hello, World!") # 输出Hello, World!
# 输出数字 # 使用自定义分隔符
print(2025) # 输出2025 print("Hello", "World", sep=", ") # 输出Hello, World
# 输出计算结果 # 自定义结束字符
print(5 + 3) # 输出8 print("Hello", end=" *** ") # 输出Hello ***
# 输出多行内容 # 将输出写入文件
print("第一行") print("Hello", file=open("output.txt", "w")) # 文件内容Hello
print("第二行")
"""
基础使用print输出你的名字
"""
print("Henry Lin")
"""
应用使用print输出1到10的数字每个数字之间用逗号和空格分隔
"""
print(1,2,3,4,5,6,7,8,9,10,sep=", ")
"""
挑战使用print将输出内容写入到一个名为output_2.txt的文件中
"""
print("Save to output_2.txt", file=open("output_2.txt", "w"))