Skip to main content

Bài 6: Xử lý file trong Python

· One min read

1. Đọc file văn bản

with open("file.txt", "r") as f:
content = f.read()
print(content)

2. Ghi file văn bản

with open("output.txt", "w") as f:
f.write("Hello, Python!")

3. Bài Tập

  1. Đọc dữ liệu từ file và đếm số dòng trong file.
  2. Viết chương trình lưu danh sách sinh viên vào file.