Python can return multiple values, which is really handy
Returns in a function can only return a value, but the return type is not restricted
Therefore, we can "return a tuple type to indirectly return multiple values".
Example is my example when I robot the framework source code:
Copy Code code 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__ was the constructor of the class, and he would get multiple return values _parse parsed back, self._purge_empty_cells (data) to Self.cells, Self._purge_empty_cells ( Comments) to self.comments
as simple as this:)