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

개념/혼자 공부하는 파이썬30

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.
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.
728x90
반응형
LIST