Programming/Python35 [Error] Attribute Error 속성 오류(Attribute Error)는 파이썬에서 발생할 수 있는 오류 중 하나입니다. 이 오류는 속성에 접근하려고 할 때 해당 속성이 존재하지 않는 경우에 발생합니다. 예를 들어, 다음과 같은 코드에서 "name" 속성에 대한 오류가 발생할 수 있습니다. class Person: def __init__(self, age): self.age = age person = Person(25) print(person.name) 위 코드에서는 "Person" 클래스의 객체를 생성하고, "name" 속성에 접근하려고 합니다. 그러나 "Person" 클래스는 "name" 속성을 정의하지 않았기 때문에, "AttributeError"가 발생하게 됩니다. 해결 방법은 "name" 속성을 추가하거나, "age" 속성을.. 2023. 3. 16. 예외 처리 사용하기 아래의 포스팅을 읽고 나면 현재 스크립트가 이해될 것이다. y = [10, 20, 30] try: index, x = map(int, input('인덱스와 나눌 숫자를 입력하세요: ').split()) print(y[index] / x) except ZeroDivisionError as eo: # as 뒤에 변수를 지정하면 에러를 받아옴 print('숫자를 0으로 나눌 수 없습니다.', eo) # e에 저장된 에러 메시지 출력 except IndexError as eo: print('잘못된 코드 : print(y[index] / x)', eo) import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as s.. 2023. 3. 15. [클래스] 메서드 오버라이딩 사용하기 [참고] 저자 본인의 공부 및 참고용으로 쓰여진 글인점을 알려드립니다. # 코딩도장의 내용입니다. https://dojang.io/mod/page/view.php?id=2387 파이썬 코딩 도장: 36.4 메서드 오버라이딩 사용하기 이번에는 파생 클래스에서 기반 클래스의 메서드를 새로 정의하는 메서드 오버라이딩에 대해 알아보겠습니다. 다음과 같이 Person의 greeting 메서드가 있는 상태에서 Student에도 greeting 메서드를 만 dojang.io Subclass 에서 Superclass 의 메서드를 새로 정의하는 method overriding class Person : def greeting(self) : print('hello') class Student(Person) : def gr.. 2023. 3. 13. [클래스] 기반 클래스의 속성 사용하기 기반 클래스에 있는 인스턴스 속성을 사용하기. class Person : def __init__(self) : print("Person __init__") self.hello = '안녕하세요.' class Student(Person) : def __init__(self) : print("Student __init__") self.school = "코딩도장" james = Student() print(james.school) print(james.hello) # 기반 클래스의 속성을 출력하려고 하면 에러가 발생한다. # 실행결과 Student __init__ 파이썬 코딩 도장 Traceback (most recent call last): File "C:\project\class_inheritance_att.. 2023. 3. 13. 이전 1 ··· 3 4 5 6 7 8 9 다음