Skip to content

Conversation

@erun1012
Copy link
Collaborator

학습 내용 요약

  • 리스트/딕셔너리/셋 에서 컴프리헨션이 어떻게 사용되는지 비교하기
  • 제너레이터의 사용법, return과 yield 의 차이점
  • __str__ vs __repr__ 와 매직메서드의 역할
  • 데코레이터의 사용법과 장단점

핵심 개념

  • 제너레이터는 yield가 값을 반환하고 다음 호출로 그 지점에서 재개된다.
  • 제너레이터 내부에서 return 을 사용하면 StopIteration이 발생한다.
  • 파이썬에 존재하는 자료형들은 클래스, 클래스 인스턴스까리 연산을 가능하게 하는 것이 매직메소드이다.
  • 데코레이터는 꾸며주는 함수 내부에 직접적 수정이나 로직 변환이 불가함
  • 데코레이터와 class 함께 사용 가능.
  • 제너레이터와 데코레이터는 복잡해질수록 디버깅이 복잡하다.

실습 예제

개념을 정리한 md 파일에 예제 코드를 참조함

참고 자료

https://tibetsandfox.tistory.com/25

https://tibetsandfox.tistory.com/28

https://tibetsandfox.tistory.com/39

https://tibetsandfox.tistory.com/42

https://tibetsandfox.tistory.com/10

체크리스트

  • 주제에 대한 핵심 내용을 다루고 있다
  • 실습 가능한 코드 예제가 포함되어 있다
  • 마크다운 문법이 올바르게 적용되었다
  • 참고 자료 출처가 명시되어 있다

@erun1012 erun1012 changed the title Session1 erun1012 Session1/erun1012 Oct 11, 2025
Copy link
Member

@rover0811 rover0811 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

결과를 맞춰보세요!

def uppercase(func):
       def wrapper():
           result = func()
           return result.upper()
       return wrapper
   
   def add_exclamation(func):
       def wrapper():
           result = func()
           return result + "!"
       return wrapper
   
   @uppercase
   @add_exclamation
   def greet():
       return "hello"
   
   print(greet())  # 결과는? "HELLO!" vs "hello!".upper()?

numbers = [1, 2, 3, 4, 5]
first, *middle, last = numbers
print(first, middle, last)
# 1 {2,3,4}, 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

실제로 이렇게 나오나요?

date2 = []
for i in range(1,6):
for j in range(1,4):
data2.append((i,j))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오타가 있어서 실행이 안될 것 같아요


```python
lst=[x*2 for x in range(5)]
gen=(x*2 for x in range(5))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list(gen) # [0, 2, 4, 6, 8]
list(gen) # ??? -> 여기서 뭐가 나올까요?

yield 1
yield 2
yield 3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   def gen_with_return():
       yield 1
       yield 2
       return "끝"  # 이 값은 어떻게 접근할까요?
       yield 3  # 이건 실행될까요?

self.x, self.y = x, y

def __eq__(self, other):
return self.x == other.x and self.y == other.y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__eq__를 구현하면 왜 __hash__도 필요할까?

set이나 dict의 키로 사용할 때 어떤 문제가 생길까요?
Python은 왜 자동으로 해시를 무효화할까요?

return func(*args, **kwargs) #7

return sentence #4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functools.wraps에 대해 좀 더 찾아보면 좋을 것 같아요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants