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

programming375

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.
python) Passing function parameters to a function def call(func): for i in range(10): func() def print_hello(): print("hello") call(print_hello) This code snippet demonstrates a simple but powerful concept in Python: passing functions as arguments to other functions. Here's how it works: ### The `call` Function - **Purpose**: Accepts a function (`func`) as its argument and calls that function 10 times within a loop. - **Implementation**: It def.. 2024. 10. 23.
728x90
반응형
LIST