Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1067945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:13:21+00:00 2026-05-16T20:13:21+00:00

I am not a python guy and I am trying to understand some python

  • 0

I am not a python guy and I am trying to understand some python code. I wonder what the last line of below code does? Is that kind of multiple objects returned? or list of 3 objects returned?

req = SomeRequestBean()
req.setXXX(xxx)
req.YYY = int(yyy)

device,resp,fault = yield req          #<----- What does this mean ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:13:21+00:00Added an answer on May 16, 2026 at 8:13 pm

    There are two things going on in that line. The easier one to explain is that the yield statement is returning a value which is a sequence, so the commas take values of the sequence and put them in the variables, much like this:

    >>> def func():
    ...     return (1,2,3)
    ...
    >>> a,b,c = func()
    >>> a
    1
    >>> b
    2
    >>> c
    3
    

    Now, the yield statement is used to create a generator, which can return a number of values rather than just one, returning one value each time yield is used. For example:

    >>> def func():
    ...     for a in ['one','two','three']:
    ...         yield a
    ...
    >>> g = func()
    >>> g.next()
    'one'
    >>> g.next()
    'two'
    >>> g.next()
    'three'
    

    In effect, the function stops at the yield statement, waiting to be asked for the next value before carrying on.

    In the example above next() gets the next value from the generator. However, if we use send() instead we can send values back to the generator which are returned by the yield statement back in to the function:

    >>> def func():
    ...     total = 0
    ...     while True:
    ...        add = yield total
    ...        total = total + add
    ...
    >>> g = func()
    >>> g.next()
    0
    >>> g.send(10)
    10
    >>> g.send(15)
    25
    

    Putting this all together we get:

    >>> def func():
    ...     total = 0
    ...     while True:
    ...         x,y = yield total
    ...         total = total + (x * y)
    ...
    >>> g = func()
    >>> g.next()
    0
    >>> g.send([6,7])
    42
    

    A generator used in this way is called a coroutine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm basically trying to do this (pseudo code, not valid python): limit = 10
next() in python does not work. What is an alternative to reading next line
I'm teaching myself Python and my most recent lesson was that Python is not
Python's access to environment variables does not accurately reflect the operating system's view of
Emacs does not recognize my correct Python path. I think it is a general
Does BeautifulSoup work with Python 3? If not, how soon will there be a
I'm aware that Python 3 fixes a lot of UTF issues, I am not
I'm a Python guy. Learning C language and I've been trying to implement Binary
I'm a PHP guy on my first day in Python-land, trying to convert a
I am debugging some python code in emacs using pdb and getting some import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.