2.1.4编写第一个 Python 程序
1. 打印“Hello, World!”
print("Hello, World!")
2. 读取文件内容
# 假设文件名为 'example.txt'  
filename = 'example.txt'  
try:  
    with open(filename, 'r', encoding='utf-8') as file:  
        content = file.read()  
        print(content)  
except FileNotFoundError:  
    print(f"The file {filename} does not exist.")  
except IOError:  
    print(f"An error occurred while reading the file {filename}.")
3. 简单的列表操作
# 创建一个列表  
my_list = [1, 2, 3, 4, 5]  
# 添加元素  
my_list.append(6)  
# 移除元素  
my_list.remove(3)  
# 列表长度  
length = len(my_list)  
# 遍历列表  
for item in my_list:  
    print(item)
					