본문 바로가기

분류 전체보기168

18. 파이썬의 예외처리& 주민번호 유효성 과제 1. 예외 예외(Exception)는 프로그램 실행 중 발생할 수 있는 예상치 못한 문제 또는 오류 상황을 의미합니다. 예외가 발생하면 프로그램은 중단되기 때문에 이를 적절하게 처리하여 중단을 방지하거나 오류에 대한 정보를 사용자에게 제공해야 합니다. 2. 예외 처리 기본 구조 'except' 뒤에 오류 코드를 넣지 않아도 예외 처리가 작동합니다. 3. Exception 클래스 Exception 클래스는 파이썬의 내장 예외 계층 구조에서 거의 모든 내장 예외의 기본 클래스입니다. 이 클래스는 사용자 정의 예외를 만들거나 특정 예외 유형을 잡기 위한 기본적인 인터페이스를 제공합니다. 4. 사용자 정의 예외 클래스를 직접 만들고 활용하기 ※. 과제1: 주민등록번호 유효성 검사 프로그램을 만들어보자 0 0 1.. 2024. 3. 19.
17. Special Method 1. Special Methods Special methods, also known as magic methods in Python, are methods that have names starting and ending with double underscores (__). These methods are automatically called by the Python interpreter when certain operators or built-in functions are used. init : This method is called when an object is created. It is used to initialize the object's attributes. str : This method i.. 2024. 3. 19.
17. 스페셜 메소드 1. 스페셜 메서드 파이썬의 스페셜 메서드 (또는 매직 메서드라고도 불림)는 더블 언더스코어(__)로 시작하고 끝나는 메서드 이름을 갖습니다. 이 메서드들은 특정 구문이나 내장 함수를 사용할 때 파이썬 인터프리터에 의해 자동으로 호출됩니다. init : 객체 생성 시 호출되는 메서드. 객체의 초기 속성을 설정하는 역할을 합니다 str : 객체를 문자열로 표현하는 메서드. print() 함수나 str() 함수 사용 시 호출됩니다 add: + 연산자를 사용할 때 호출되는 메서드. 두 객체의 합을 계산합니다. len: len() 함수 사용 시 호출되는 메서드. 객체의 길이를 반환합니다. getitem: 인덱싱 연산 사용 시 호출되는 메서드. 객체의 특정 인덱스에 위치한 요소를 반환합니다 call: 객체를 함수.. 2024. 3. 19.
16. Inheritance in Python 1. Inheritance Inheritance in Python is a mechanism that allows one class to inherit the properties and methods of another class. This enables code reuse and extensibility. By default, all classes in Python inherit from a base class called object. Base Class (or Parent Class): The class from which inheritance is derived. Derived Class (or Child Class): The class that inherits properties and meth.. 2024. 3. 19.