예외처리

try: # 꼭 들어가야 함
    예외가 발생할 수 있는 코드

except: # 꼭 들어가야 함
    예외가 발생했을 때 실행할 코드

except Exception as exception: # 예외 코드와 관련된 객체
    type(exception) # ValueError, IndexError
    print(exception) 

else: # 선택
    예외가 발생하지 않았을 때 실행할 코드

finally: # 선택
    예외와 관계없이 무조건 실행하는 코드
    ex) file.close()

모듈

어떤 기능을 가지고 있는 집합체

모듈 사용 방법

import 모듈 # import math
ex)
import math as m
math.pi
m.pi

from math import pi, sin, cos
from math import *