Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
전문가를 위한 파이썬(2판)
by
루시아누 하말류
,
강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from
전문가를 위한 파이썬(2판)
686
4
부
제어 흐름
17
.
5
.
4
제너레이터의 작동 방식
본체 안에
yield
키워드가 있는 함수는 모두 제너레이터 함수다. 제너레이터 함수는 호출되면
제너레이터 객체를 반환한다. 즉, 제너레이터 함수는 제너레이터 팩토리라고 할 수 있다.
TIP
일반 함수와 제너레이터 함수의 유일한 구문 차이는 제너레이터 함수가 본체 안 어디에선가
yield
키
워드를 사용한다는 점밖에 없다. 제너레이터 함수는
def
가 아니라
gen
과 같은 새로운 키워드를 사용해야 한
다고 주장하는 사람도 있었지만, 귀도 반 로섬은 동의하지 않았다. 그는 ‘
PEP
255
–간단한 제너레이터
Simple
Generators
’ 제안서(
https://fpy.li/pep255
)에 자신의 의견을 피력했다.
5
제너레이터의 작동을 잘 보여 주는 간단한 예는 다음과 같다.
6
예제
17-6
숫자 세 개를 생성하는 제너레이터 함수
>>>
def gen_123():
...
yield 1
❶
...
yield 2
...
yield 3
...
>>>
gen_123 # doctest: +ELLIPSIS
<function gen_123 at 0x...> ❷
>>>
gen_123() # doctest: +ELLIPSIS
<generator object gen_123 at 0x...> ❸
>>>
for i in gen_123():
❹
... ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial
You might also like
전문가를 위한 리액트
테자스 쿠마르
데이터로 전문가처럼 말하기
칼 올친
개발자를 위한 머신러닝&딥러닝
로런스 모로니
고성능 파이썬(2판)
오현석, 미샤 고렐릭, 이안 오스발트
Publisher Resources
ISBN: 9791169211772