분류 전체보기30 Exception 구문 1 try: 실행할 코드 except 예외이름: 예외가 발생했을 때 처리하는 코드 구문 2 : as 이용 try: 실행할 코드 except 예외 as 변수: 예외가 발생했을 때 처리하는 코드 구문 3 try: 실행할 코드 except: 예외가 발생했을 때 처리하는 코드 else: 예외가 발생하지 않았을 때 실행할 코드 finally: 예외 발생 여부와 상관없이 항상 실행할 코드 구문 4 : raise raise 예외명('에러메시지') 구문 5 : re - raise # re-raise def three_multiple(): try: x = int(input('3의 배수를 입력하세요: ')) if x % 3 != 0: # x가 3의 배수가 아니면 raise Exception('3의 배수가 아닙니다.'.. 2022. 11. 23. decorator 사용법 https://dojang.io/mod/page/view.php?id=2427 파이썬 코딩 도장: 42.1 데코레이터 만들기 Unit 42. 데코레이터 사용하기 파이썬은 데코레이터(decorator)라는 기능을 제공합니다. 데코레이터는 장식하다, 꾸미다라는 뜻의 decorate에 er(or)을 붙인 말인데 장식하는 도구 정도로 설명할 수 있습 dojang.io 클로저 사용법 : https://fiasco-at-python.tistory.com/46 0. 데커레이터 도입 개념 # 함수 출력 결과 확인 def hello(): print('hello 함수 시작') print('hello') print('hello 함수 끝') def world(): print('world 함수 시작') print('world'.. 2022. 11. 23. closure 사용법 https://dojang.io/mod/page/view.php?id=2364 파이썬 코딩 도장: 33.1 변수의 사용 범위 알아보기 Unit 33. 클로저 사용하기 이번에는 변수의 사용 범위와 함수를 클로저 형태로 만드는 방법을 알아보겠습니다. 참고로 클로저는 개념이 다소 어려울 수 있으므로 변수의 사용 범위부터 알아본 뒤 dojang.io 함수안의 함수 def print_hello(): hello = 'Hello, world!' def print_message(): print(hello) print_message() print_hello() 클로저 클로저를 사용하면 프로그램의 흐름을 변수에 저장할 수 있습니다. 즉, 클로저는 지역 변수와 코드를 묶어서 사용하고 싶을 때 활용합니다. 또한, 클로저에 속.. 2022. 11. 23. [ Think Python ] function object A function object is a value you can assign to a variable or pass as an argument. For example, do_twice is a function that takes a function object as an argument and calls it twice: Here’s an example that uses do_twice to call a function named print_spam twice: def do_twice(f): f() f() def print_spam(): print('spam') print('spam') do_twice(print_spam) Exercise 3-2. 1. Type this example into a sc.. 2022. 11. 20. 이전 1 2 3 4 5 ··· 8 다음