본문 바로가기
728x90
반응형
SMALL

개념175

python) custom exception class class Custom(Exception): def __init__(self): super().__init__() raise Custom In this simplified example, a custom exception class named `Custom` is defined, which inherits from Python's built-in `Exception` class. The `__init__` method of this class calls the initializer of the base `Exception` class using `super().__init__()`. This setup ensures that `Custom` behaves like a standard exception i.. 2024. 11. 1.
python) Class Definitions and Inheritance class Parent: def __init__(self): self.value = "Test" print("Parent class __init()__ mathod is called") def test(self): print("Parent class of test() mathod") class Child(Parent): def __init__(self): super().__init__() print("Child class __init()__ mathod is called") child = Child() child.test() print(child.value) ### Class Definitions and Inheritance - **`class Parent:`** Defines a base (or par.. 2024. 10. 31.
python) Put only things that can be converted to numbers into a list list_input_a = ["12", "34", "56", "321", "hello" ,"256"] list_number=[] for item in list_input_a: try: float(item) list_number.append(item) except: pass finally: print(f"end list file : {list_input_a[list_input_a.index(item):]}") print(f"{list_input_a} 내부에 있는 숫자는 {list_number}입니다.") This code snippet filters out numeric strings from a list and prints the remaining elements of the list after each.. 2024. 10. 30.
python) Overriding class Custom(Exception): def __init__(self): # Corrected from __int__ to __init__ super().__init__() print("make the create of Error") def __str__(self): return "create Error" raise Custom() Your code defines a custom exception class named `Custom`, intended to demonstrate custom exception handling in Python. However, there's a small typo in your class definition that affects its intended functi.. 2024. 10. 29.
728x90
반응형
LIST