Python - 처음 시작하는 파이썬 13장 날짜와 시간 + 연습문제

학습내용

연습문제

13.1

현재날짜를 문자열로 작성하여 today.txt 파일에 저장한다.

today.txt

2021-6-6

13.2

today.txt. 파일을 읽어 today_string 문자열에 저장한다.

>>> f = open("today.txt", 'r')
>>> today_string = f.readline()
>>> today_string
'2021-6-6'
>>>

13.3

today_string 문자열을 날짜로 파싱한다.

from datetime import date
>>> year, month, day = today_string.split('-')
>>> today = date(int(year), int(month), int(day))
>>> today
datetime.date(2021, 6, 6)
>>>    

13.4

여러분이 태어난 날의 date 객체 생성

>>> birthday = date(2001, 9, 14)
>>> birthday
datetime.date(2001, 9, 14)

13.5

무슨 요일에 태어났는가?

태그:

업데이트:

댓글남기기