This article mainly introduces how python functions return multiple values. you can use python to return multiple values, which is really convenient.
Only one value can be returned for return in the function, but the return type is not limited.
Therefore, we can "return a tuple type to indirectly return multiple values ".
The example is my example of the robot framework source code:
The code is as follows:
Def _ init _ (self, cells ):
Self. cells, self. comments = self. _ parse (cells)
Def _ parse (self, row ):
Data = []
Comments = []
For cell in row:
Cell = self. _ collapse_whitespace (cell)
If cell. startswith ('#') and not comments:
Comments. append (cell [1:])
Elif comments:
Comments. append (cell)
Else:
Data. append (cell)
Return self. _ purge_empty_cells (data), self. _ purge_empty_cells (comments)
At that time, _ init _ is the class constructor, and he will get multiple return values parsed by _ parse, self. _ purge_empty_cells (data) is assigned to self. cells, self. _ purge_empty_cells (comments) is assigned to self. comments
That's simple :)