전체 글
-
제너레이터(발생자)Python 2023. 10. 24. 15:39
제너레이터는 이터레이터를 만들어 주는 함수 이터레이터는 __iter__, __next__ 또는 __getitem__ 메서드를 구현해야 하지만 제너레이터는 함수 안에서 yield 키워드만 사용하면 끝 > 이터레이터보다 훨씬 간단하게 작성 가능 # yield 값 def number_generator(): yield 0 yield 1 yield 2 for i in number_generator(): print(i) # 실행 결과 0 1 2 제너레이터 객체가 이터레이터인지 확인 g = number_generator() print(g) print(dir(g)) # 실행 결과 ['__class__', '__del__', '__delattr__', '__dir__', '__doc__', '__eq__', '__for..
-
이터레이터(반복자)Python 2023. 10. 24. 12:16
이터레이터(iterator)는 값을 차례대로 꺼낼 수 있는 객체 파이썬에서는 이터레이터만 생성하고 값이 필요한 시점이 되었을 때 값을 만드는 방식 사용 > 데이터 생성을 뒤로 미루는 것(지연 평가) 반복 가능한 객체 알아보기 > 문자열, 리스트, 딕셔너리, 세트 객체에 __iter__ 메서드가 들어 있는지 확인, dir 함수로 확인 가능 >>> dir( [1, 2, 3] ) ['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__g..
-
예외 처리Python 2023. 10. 23. 16:43
try except로 사용 # try: # 실행할 코드 # except: # 예외가 발생했을 때 처리하는 코드 try: x = int(input('나눌 숫자 입력: ')) y = 10 / x print(y) except: # 예외가 발생했을 때 실행됨 print('오류 발생') # 실행 결과 나눌 숫자 입력: 0 오류 발생 예외 발생 시 해당 줄에서 바로 코드 실행 중단, 바로 except로 넘어가 코드 실행 try의 y = 10 / x, print(y) 모두 실행되지 x try 코드에서 에러가 발생했을 때만 except 코드가 실행됨 특정 예외만 처리 # try: # 실행할 코드 # except 예외이름: # 예외가 발생했을 때 처리하는 코드 y = [10, 20, 30] try: index, x = ..
-
클래스(3)Python 2023. 10. 23. 12:38
클래스의 상속 사용 사람 클래스로 학생 클래스 만들기 # class 기반클래스이름: # 코드 # class 파생클래스이름(기반클래스이름): # 코드 class Person: def greeting(self): print('안녕하세요') class Student(Person): def study(self): print('공부하기') james = Student() james.greeting() # 안녕하세요: 기반 클래스 Person의 메서드 호출 james.study() # 공부하기: 파생 클래스 Student에 추가한 study 메서드 maria = Person() maria.greeting() maria.study() # 에러, Person에는 study 메서드가 없음 maria.study() ^^^..
-
연습 예제HTML 2023. 10. 20. 17:30
연습 문제 1 기업 연혁 2018 ~ 현재 환경과 사람을 존중하는 기업 '환경 사랑' 환경 관련 우수기업 대통령상을 수상하다. 2021 환경사랑 수원 전시장 오픈 2020 환경사랑 광주 전시장 오픈 2019 환경사랑 대전 전시장 오픈 2018 환경사랑 서울 전시장 오픈 연습 문제 2 아직 푸는 중... 알림 8월 3일 쿠킹 클래스 연기합니다. 09.30 8월 3일 쿠킹 클래스 연기합니다. 09.30 8월 3일 쿠킹 클래스 연기합니다. 09.30 8월 3일 쿠킹 클래스 연기합니다. 09.30 8월 3일 쿠킹 클래스 연기합니다. 09.30 자유 게시판 안녕하세요. 반갑습니다. 09.30 안녕하세요. 반갑습니다. 09.30 안녕하세요. 반갑습니다. 09.30 안녕하세요. 반갑습니다. 09.30 안녕하세요. 반..
-
요소 배치HTML 2023. 10. 19. 17:33
절대 위치를 사용한 요소 배치 자손의 position 속성에 absolute 키워드를 적용하려면 부모에 height 속성을 입력 Dommy Text Dommy Text .circle { position: absolute; width: 100px; height: 100px; border-radius: 40% 40%; } border-radius 숫자 줄이면 덜 동그란 원 만들 수 있음 위 기능 이용해 CSS로 오륜기 만들기 요소 중앙 배치 요소의 중앙 배치 요소를 고정 위치에 배치 고정 바 배치 Lorem ipsum dolor sit amet, consectetur adipisicing elit. Lorem ipsum dolor sit amet consectetur adipisicing elit. Lore..
-
수평, 중앙, One True 정렬 레이아웃HTML 2023. 10. 19. 15:22
수평 정렬 레이아웃 Lorem, ipsum dolor sit amet consectetur adipisicing elit. Voluptas totam magnam molestiae quas, eaque in voluptatum labore consequatur necessitatibus accusamus. Esse, dignissimos expedita laudantium dolor atque mollitia eos consequatur libero! 메뉴 - 1 메뉴 - 2 메뉴 - 3 메뉴 - 4 Lorem ipsum dolor sit amet consectetur adipisicing elit. Similique, perferendis sed quam optio ullam nobis voluptas..
-
클래스(2)Python 2023. 10. 18. 16:03
클래스와 인스턴스 속성 알아보기 클래스 속성 사용하기 class Person: bag = [] # 객체 관계없이 공통 사용 def put_bag(self, stuff): self.bag.append(stuff) james = Person() # james 객체 생성 james.put_bag('책') maria = Person() # maria 객체 생성 maria.put_bag('열쇠') print(james.bag) print(maria.bag) # 실행 결과 ['책', '열쇠'] ['책', '열쇠'] 클래스 속성은 클래스에 속해 있으며, 모든 인스턴스에서 공유 put_bag 메서드에서 클래스 속성 bag에 접근할 때 self를 사용했고, self는 현재 인스턴스를 뜻하므로 클래스 속성을 지칭하기에 모..