For purpose of illustration, in pseudocode:  function addint(x,y,answer: integer)   var     condition: integer;    begin     if ((MAXINT - x) &lt; y) then       begin         answer := x;         condition := 1;           end      else        begin          answer := x + y;          condition := 0;        end;         return condition;    end.   In the example, answer is either called by reference or is a pointer. It holds the actual result to be passed back to the caller, and the function itself holds the exit code. The exit code follows the C tradition: 0 for normal exit and other values for abnormal exit. It is required because the operation is not always successful, depending on the values of x and y.  Is there anyway to write the same style of functions in Python without major modifications?
The canonical way to return multiple values in languages that support it is often . Option: Using a tuple Consider this trivial example: def f(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return (y0, y1, y2)  However, this quickly gets problematic as the number of values returned increases. What if you want to return four or five values? Sure, you could keep tupling them, but it gets easy to forget which value is where. It's also rather ugly to unpack them wherever you want to receive them. Option: Using a dictionary The next logical step seems to be to introduce some sort of 'record notation'. In Python, the obvious way to do this is by means of a dict. Consider the following: def g(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return {'y0': y0, 'y1': y1 ,'y2': y2}  (Just to be clear, y0, y1, and y2 are just meant as abstract identifiers. As pointed out, in practice you'd use meaningful identifiers.) Now, we have a mechanism whereby we can project out a particular member of the returned object. For example, result['y0']  Option: Using a class However, there is another option. We could instead return a specialized structure. I've framed this in the context of Python, but I'm sure it applies to other languages as well. Indeed, if you were working in C this might very well be your only option. Here goes: class ReturnValue:   def __init__(self, y0, y1, y2):      self.y0 = y0      self.y1 = y1      self.y2 = y2  def g(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return ReturnValue(y0, y1, y2)  In Python the previous two are perhaps very similar in terms of plumbing - after all { y0, y1, y2 } just end up being entries in the internal __dict__ of the ReturnValue. There is one additional feature provided by Python though for tiny objects, the __slots__ attribute. The class could be expressed as: class ReturnValue(object):   __slots__ = [&quot;y0&quot;, &quot;y1&quot;, &quot;y2&quot;]   def __init__(self, y0, y1, y2):      self.y0 = y0      self.y1 = y1      self.y2 = y2  From the :  The __slots__ declaration takes a sequence of instance variables and reserves just enough space in each instance to hold a value for each variable. Space is saved because __dict__ is not created for each instance.  Option: Using a  (Python 3.7+) Using Python 3.7's new dataclasses, return a class with automatically added special methods, typing and other useful tools: @dataclass class Returnvalue:     y0: int     y1: float     y3: int  def total_cost(x):     y0 = x + 1     y1 = x * 3     y2 = y0 ** y3     return ReturnValue(y0, y1, y2)  Option: Using a list Another suggestion which I'd overlooked comes from Bill the Lizard: def h(x):   result = [x + 1]   result.append(x * 3)   result.append(y0 ** y3)   return result  This is my least favorite method though. I suppose I'm tainted by exposure to Haskell, but the idea of mixed-type lists has always felt uncomfortable to me. In this particular example the list is -not- mixed type, but it conceivably could be. A list used in this way really doesn't gain anything with respect to the tuple as far as I can tell. The only real difference between lists and tuples in Python is that lists are , whereas tuples are not. I personally tend to carry over the conventions from functional programming: use lists for any number of elements of the same type, and tuples for a fixed number of elements of predetermined types. Question After the lengthy preamble, comes the inevitable question. Which method (do you think) is best?
Problem requiring/including plugin files with plugin_dir_path( __FILE__ ) I am trying to write a WordPress plug-in. In my project I have three PHP files.   My plug-in file Widget for the plug-in Data installation   I need to install data table on plug-in activation. For that sake I wrote code to create table for my plug-in in data installation file. But I am not able to create data table using this file.  My code for include data installation file and widget file in my plug-in file is  define ( 'OTHER_FILES_PATH', plugin_dir_path( __FILE__ ) ); require_once( OTHER_FILES_PATH . '/data_installation.php' ); require_once( OTHER_FILES_PATH . '/plugin_widget.php' );   My problem is when I put my data installation code in my plug-in file it's working fine but when I put it in separate file (data installation) I am unable to create tables for my plug-in.  Please let me know if I am making any mistake. How to prevent search engines from indexing a single page of my website? I have two tables A &amp; B. Table A id | name | num  Table B id | date | roll  id in table B is a foreign key which relates to the id in table A. I want to get the contents of table B where id is given and also along with that data, I need the name whose id is given from table A. NOTE: cannot use multiple queries separated by commas; need to do both the SELECTs in one query. newcommand vs. DeclareMathOperator As far as I understand, whatever can be done using DeclareMathOperator can also be achieved using newcommand, but not the other way around. If this is the case, what are the circumstances where DeclareMathOperator is the better choice? When should I take solely newcommand?  I found a question regarding , and I wonder what other aspects should be taken into consideration when it comes to choosing which method to use when defining math operators. How to distinguish between American Indians and Indian Indians in native English (language) parlance? How to distinguish between American Indians and Indian Indians in native English (language) parlance?  Can I say Indian Indian to say Indian from Asia compared to the Native Americans? How can I make a procedural polished granite material? Are tile bonuses counted twice if 2 new words are formed? An example:    O  O?   There is a triple letter tile to the right of the bottom O, indicated with a ?.  If I place an X on it, making the words OX (vertical) and OX (horizontal), do I score 50 points (scoring the tile twice) or 34 (scoring it once)? Change all file type associations from one program to another Determine Whether Two Date Ranges Overlap Given two date ranges, what is the simplest or most efficient way to determine whether the two date ranges overlap?  As an example, suppose we have ranges denoted by DateTime variables StartDate1 to EndDate1 and StartDate2 to EndDate2. Acro package provides "! Missing number, treated as zero." after update to acro-v2.7b How to find the inverse modulo $m$? Let $M$ be an A-module and $f \in \text{End}(M)$ an idempotent endomorphism. Show that $M = \ker(f) \oplus \ker (f-\text{id}_M)$. I don't know how to approach this exercise, using only properties of modules and direct sums, without projections. Can you help me? Thanks in advance. How do I iterate over a range of numbers defined by variables in Bash? How do I iterate over a range of numbers in Bash when the range is given by a variable?  I know I can do this (called "sequence expression" in the Bash ):   for i in {1..5}; do echo $i; done   Which gives:     1    2    3    4    5   Yet, how can I replace either of the range endpoints with a variable? This doesn't work:  END=5 for i in {1..$END}; do echo $i; done   Which prints:     {1..5} Could I replace headphones NIMH battery with Lithium Ion phone battery of the same voltage? Drive shape key based on relative camera orientation? Which LaTeX to install on Linux? Which LaTeX distribution would you recommend for using on Linux from command line? I am looking for one with most complete coverage of packages. How to restore a system after accidentally removing all kernels? Recommended books for advanced undergraduate electrodynamics What books are recommended for an advanced undergraduate course in electrodynamics? How to get from Heathrow Airport to King's Cross, London? My wife and I will be arriving in London via Heathrow Airport (LHR) and are staying at a hotel near King's Cross station. So, we were wondering what the best (which means fastest but also easiest when carrying two large pieces of luggage and two carry-ons) way to get from LHR to King's Cross?  I gather that, with only one changeover, we can take the Tube. However, in the interest of other passengers, we thought it would be best to take a taxi, or maybe a bus?  Thoughts? Why is $\langle \textbf R \rangle =Tr \rho R$ here $\rho$ is the state density matrix