yield keyword in Python

0 votes
What does 'yield' do in Python?
Jul 9, 2019 in Python by Nisa
• 1,090 points
141 views

1 answer to this question.

0 votes

The yield keyword is used along with generator functions to generate iterators. 

EXAMPLE:

def simpleGeneratorFun(): 
    yield 'a'           
    yield 'b'           
    yield 'c'           
for x in simpleGeneratorFun():  
    print(x)

OUTPUT:

a
b
c
answered Jul 9, 2019 by Wajiha
• 1,950 points

Related Questions In Python

0 votes
1 answer

How to use “raise” keyword in Python

You can use it to raise errors ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 58,100 points
160 views
0 votes
1 answer

What is the use of “assert” keyword in Python?

You can try the following in a ...READ MORE

answered Oct 15, 2018 in Python by Priyaj
• 58,100 points
228 views
+1 vote
1 answer

What does the Raise keyword do in Python?

Hi! I think I can answer this - ...READ MORE

answered Jan 25, 2019 in Python by Nymeria
• 3,520 points
234 views
0 votes
1 answer

assert keyword in python is used for what purpose?

The assert keyword is used while debugging ...READ MORE

answered May 24, 2019 in Python by Taj
• 1,080 points
738 views
0 votes
0 answers

pass optional or keyword parameters from one function to another in python?

How can I pass optional or keyword ...READ MORE

Jul 24, 2019 in Python by Hari
206 views
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,890 points
12,434 views
+2 votes
2 answers

How can I create a new file in Python?

You can try the below code which ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
387 views
0 votes
1 answer

What does the “yield” keyword do?

To understand what yield does, you must understand what generators are. ...READ MORE

answered Dec 16, 2020 in Python by Gitika
• 65,870 points
35 views
0 votes
1 answer

What is timedelta in python?

It represents a duration which is basically ...READ MORE

answered Aug 7, 2019 in Python by Wajiha
• 1,950 points
110 views
0 votes
1 answer

Slicing a list using a variable, in Python

Yes its possible. Use the following piece ...READ MORE

answered Jul 2, 2019 in Python by Wajiha
• 1,950 points
277 views