입출력

print("a", "b", "c", sep=",", end="?")
#end: 문장이 마지막을 줄바꿈이 아닌 물음표로 바꿔달라
import sys
print("python", "Java", file=sys.stdout)
print("python", "Java", file=sys.stderr)

#시험성적
scores = {"수학":0, "영어":50, "코딩":100}
for subject, score in scores.items():
    # print (subject, score) <- 그냥 출력
    print (subject.ljust(8), str(score).rjust(4), sep=":") # 정렬

#은행 대기 순번표
for num in range (1, 21):
    print("대기번호 : "+str(num).zfill(3)) #빈 공간은 0으로 채움

answer = input("아무 값이나 입력하세요 : ") # 항상 문자열 형태로 저장이 됨

#다양한 출력 포맷
#빈 자리는 빈공간으로 두고, 오른쪽 정렬을 하되, 총 10자리 공간을 확보
print("{0: >10}".format(500))
#양수일 떄는 +로 표시, 음수일 떄는 -로 표시
print("{0: >+10}".format(500))
#왼쪽 정렬하고, 빈칸을 _로 채움
print("{0:_<+10}".format(500))
#3자리마다 , 찍기
print("{0:,}".format(10000000))
#3자리마다 , 찍기, +- 부호도 나오게
print("{0:+,}".format(10000000))
#3자리마다 , 부호, 자릿수 확보, 빈자리는 ^로 채움
print("{0:^<+30,}".format(10000000))
#소수점 출력
print("{0:f}".format(5/3))
#3번째 자리에서 반올림, 소수점 2번째까지만 표시
print("{0:.2f}".format(5/3))
#파일 입출력
score_file = open("score.txt", "w", encoding="utf8")
print("수학 : 0", file=score_file)
print("영어 : 0", file=score_file)

score_file = open("score.txt", "a", encoding="utf8")
score_file.write("과학 : 80")
score_file.write("\\n코딩 : 100")
score_file.close()

score_file = open("score.txt", "r", encoding="utf8") #파일 읽기
print(score_file.read())
score_file.close()
#줄별로 읽기
print(score_file.readline(), end="")
print(score_file.readline(), end="")
score_file.close()

#리스트에 넣기
score_file = open("score.txt", "r", encoding="utf8")
lines = score_file.readlines()
for line in lines:
    print(line, end="")

score_file.close()
#피클=데이터를 파일 형태로 저장
import pickle
profile_file = open("profile.pickle", "wb")
profile = {"이름":"박명수", "나이":30, "취미":["축구", "골프"]}
print(profile)
pickle.dump(profile, profile_file) #profile에 있는 정보를 file에 저장
profile_file.close()

profile_file = open("profile.pickle", "rb")
profile = pickle.load(profile_file) #file에 있는 정보를 profile에 불러오기
print(profile)
profile_file.close()
#저장된 데이터를 close없이 불러오기
import pickle

with open("profile.pickle", "rb") as profile_file:
    print(pickle.load(profile_file))

# 파일 만들기
with open ("study.txt", "w", encoding="utf8")as study_file:
    study_file.write("파이썬")
#읽기
with open("study.txt", "r", encoding="utf8")as study_file:
    print(study_file.read())