yield keyword in Python

0 votes
What does 'yield' do in Python?
Jul 9 in Python by Nisa
• 1,090 points
33 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 by Wajiha
• 1,920 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
• 56,920 points
49 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
• 56,920 points
86 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 in Python by Nymeria
• 3,520 points
78 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 in Python by Taj
• 1,040 points
87 views
0 votes
0 answers
+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,810 points
202 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,420 points
121 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

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

What is timedelta in python?

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

answered Aug 7 in Python by Wajiha
• 1,920 points
32 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 in Python by Wajiha
• 1,920 points
28 views