What is difference between yield and return?



What is difference between yield and return?..

Answer / Satyanarayan Dash

Answer: 'Yield' and 'return' are both used for controlling flow in Python functions, but they have different purposes. 'Return' ends a function and returns a value to the caller, while 'yield' generates a series of values (a generator). Generators can be useful when dealing with large data sets or resource-intensive tasks.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Write a program to check whether the object is of a class or its subclass.

1 Answers  


Write a coding in find a largest among three numbers?

1 Answers  


Define pyramid in python?

1 Answers  


Is python completely free?

1 Answers  


What is the process to calculate percentiles with numpy?

1 Answers  


How to use decorators in Python?

2 Answers  


How do you install a sphinx python?

1 Answers  


What is the zip() function in python?

1 Answers  


What is the keyword to import a module in python?

1 Answers  


Can __ init __ return value?

1 Answers  


Is node better than python?

1 Answers  


Which statement of python is used whenever a statement is required syntactically but the program needs no action?

1 Answers  


Categories