728x90 반응형 SMALL 전체 글375 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. python) size comparison function class Student: def __init__(self, name, korean, math, english, science): self.name = name self.korean = korean self.math = math self.english = english self.science = science def get_sum(self): return self.korean + self.math + self.english + self.science def get_average(self): return self.get_sum() / len(self.get_sum()) def __str__(self): return "{}\t{}\t{}".format(self.name, self.get_sum(), self.. 2024. 10. 28. python) Declare a function inside a class class Student: def __init__(self,name,korean,math,english,science): self.name = name self.korean = korean self.math = math self.english = english self.science = science def get_sum(self): return self.korean + self.math + self.english + self.science def get_average(self): return (self.korean + self.math + self.english + self.science)/4 def get_to_string(self): return "{}\t{}\t{}".format(self.name.. 2024. 10. 27. 이전 1 ··· 23 24 25 26 27 28 29 ··· 94 다음 728x90 반응형 LIST