When.com Web Search

Search results

  1. Results From The WOW.Com Content Network
  2. We can make a tuple right on the return line; or we can use a dictionary, a namedtuple (Python 2.6+), a types.simpleNamespace (Python 3.3+), a dataclass (Python 3.7+), or some other class (perhaps even one we write ourselves) to associate names with the values that are being returned; or we can accumulate values from a loop in a list; etc. etc.

  3. The efficiency of both forms is comparable, the underlying machine code has to perform a jump if the if condition is false anyway. Note that Python supports a syntax that allows you to use only one return statement in your case: return A+1 if A > B else A-1. answered Feb 8, 2012 at 10:25. Frédéric Hamidi.

  4. return means "output this value from this function". print means "send this value to (generally) stdout" In the Python REPL, a function's return value will be output to the screen by default (this isn't the same as printing it). This output only happens at the REPL, not when running code from a .py file.

  5. how to return values in a python dictionary - Stack Overflow

    stackoverflow.com/questions/75512990/how-to-return-values-in-a-python-dictionary

    You might like to take a look at the documentation on dictionaries and how to access values with keys [as well as lists, the values of which can be accessed with indices], but below are some examples with favsDict: favsDict['Jake'] should return ['red', 'pizza', 'soda'] favsDict['Tim'][0] should return 'red'.

  6. python - How to get the return value from a thread?

    stackoverflow.com/questions/6893968

    If you really want join() to return the return value of the called function, you can do this with a Thread subclass like the following: from threading import Thread. def foo(bar): print 'hello {0}'.format(bar) return "foo". class ThreadWithReturnValue(Thread):

  7. If you want both the name and the age, you should be using .items() which gives you key (key, value) tuples:. for name, age in mydict.items(): if age == search_age: print name

  8. Is there a way to return literally nothing in python?

    stackoverflow.com/questions/15650614

    There is no such thing as "returning nothing" in Python. Every function returns some value (unless it raises an exception). If no explicit return statement is used, Python treats it as returning None. So, you need to think about what is most appropriate for your function. Either you should return None (or some other sentinel value) and add ...

  9. Generally, you return the value. Once you've done that, you can assign a name to the return value just like anything else: def randombb(): return random.random() a = randombb() As a side note -- The python tutorial is really great for anyone looking to learn a thing or two about the basics of python. I'd highly recommend you check it out.

  10. python - Return value from thread - Stack Overflow

    stackoverflow.com/questions/1886090

    Use lambda to wrap your target thread function and pass its return value back to the parent thread using a queue. (Your original target function remains unchanged without extra queue parameter.) (Your original target function remains unchanged without extra queue parameter.)

  11. Using python's mock patch for changing the return value of a method called in a method used within another method 0 Use python's mock patch to mock the value of parent class attribute(set by a calling an imported module) while testing a child class