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

programming380

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.
python) class parameter class student: count = 0 def __init__(self, name, korean, english, math, science): self.name = name self.korean = korean self.math = math self.english = english self.science = science student.count += 1 print("{}번째 학생이 생성됨".format(student.count)) students = [ student("윤인성", 87,98,88,95), student("연하진",92,98,96,98), student("구지연",98,96,90,89), student("나선주",88,86,64,87), student("윤아린",98,99,78,80.. 2024. 10. 26.
python) class function class Student: count = 0 students = [] @classmethod def print(cls): print("========Student list========") print("name\tsum\taverage") for student in cls.students: print(str(student)) print("-------- --------- --------") def __init__(self, name, korean, english, math, science): self.name = name self.korean = korean self.math = math self.english = english self.science = science self.count += 1 Stu.. 2024. 10. 25.
python) function decorator def test(function): def wrapper(): print("start") function() print("end") return wrapper @test def hello(): print("hello") hello() This code snippet is an example of a Python decorator in action. Decorators are a powerful and expressive feature of Python that allows you to modify the behavior of functions or methods. Here's a breakdown of how this particular code works: ### The `test` Decorator .. 2024. 10. 24.
728x90
반응형
LIST