Programming/Python

[Python] 파이썬 파일입출력

prinha 2025. 2. 2. 14:37
728x90
반응형
# 파일입출력
# input(), print() X
# 프로그램에 유의미한 데이터를 읽기/저장/출력

# 1) 파일 열기
# w : 쓰기 모드 write 덮어쓰기
# a : 추가 모드 append 이어쓰기
# r : 읽기 모드 read
file = open("data.txt", "w")
file = open("data.txt", "a")
file = open("data.txt", "r")

# 2) 파일 작업 
file.write("start python") # 쓰기/추가 모드
data = file.read() # 읽기 모드

# 3) 파일 닫기
file.close()
728x90
반응형