03-1 불 자료형과 if 조건문
Boolean, 불린, 불리언 True와 False값만 가질 수 있으며 비교연산자를 통해 만들 수 있다.
불끼리는 논리연산자를 사용할 수 있다.
https://standout.tistory.com/1147
자바의 정석 Chapter03: 연산자
들어가기전에, 연산자에 대해 배워갈때 알고있어야하는점은, 연산자의 종류는 기술/코딩의 발전에 따라 그 종류가 방대하기에 한번에 학습하기를 목표로 하기보다는 자주 사용하는 연산자를
standout.tistory.com
if조건문은 조건에 따라 코드를 실행하거나 실행하지않고 싶을때 사용하는 구문
datetime + if문 오전과 오후를 구분

import datetime
now = datetime.datetime.now()
print(now)
print(now.year)
print(now.month)
print(now.day)
print(now.hour)
print(now.minute)
print(now.second)
print(now.microsecond)
print(now.strftime("%Y-%m-%d %H:%M:%S"))
if now.hour < 12:
print("Good morning")
else:
print("Good afternoon")
계절을 구분

if 3 <= now.month <= 5:
print("Spring")
elif now.month == 6:
print("Summer")
elif now.month == 7:
print("Autumn")
elif now.month >= 8:
print("Winter")
홀수 짝수 구분

number = input("Enter a number: ")
last_character = number[-1]
last_number = int(last_character)
if last_number == 0 \
or last_number == 2 \
or last_number == 4 \
or last_number == 6 \
or last_number == 8:
print("The number is even")
else:
print("The number is odd")
더 간단한 방법
if number in "02468":
print("The number is even")
else:
print("The number is odd")
if int(number) % 2 == 0:
print("The number is even")
else:
print("The number is odd")

03-2 if~else와 elif 구문
if조건, 조건이 참일때, 거짓일때 실행하는 문장
elif 조건이 참이 아닐때의 조건문장
else 조건이 참이 아닐때의 외 문장
https://standout.tistory.com/177
조건문, if와 switch
if문과 switch는 비슷하나, 범위는 if문, 값은 switch문이 좋다. if는 그 뜻이 "만약에~"기 때문에 쉽게 이해할 수 있으나 switch-case문은 생소할 수 있는데, 카페에서 메뉴를 선택하는 키오스크를 연상하
standout.tistory.com
pass 키워드 전체 골격을 잡아놓고 내부에서 처리할 내용은 차근차근 생각하며 만들겠다는 의도
if 3 <= now.month <= 5:
print("Spring")
elif now.month == 6:
print("Summer")
elif now.month == 7:
print("Autumn")
elif now.month >= 8:
print("Winter")
else:
pass
'Personal > Book' 카테고리의 다른 글
| 혼자 공부하는 파이썬 - Chapter 05 함수 (0) | 2026.05.21 |
|---|---|
| 이것이 MySQL이다 - part01_MySQL 설치 및 DB 구축과정 미리 실습하기 (0) | 2026.05.12 |
| 혼자 공부하는 파이썬 - Chapter 04 반복문 (0) | 2026.05.11 |
| 혼자 공부하는 파이썬 - Chapter 01 파이썬 시작하기 (0) | 2026.05.07 |
| 혼자 공부하는 파이썬 - Chapter 02 자료형 (0) | 2026.05.07 |