Why?


#1



https://www.codecademy.com/de/courses/python-beginner-en-4XuFm/0/7?curriculum_id=4f89dab3d788890003000096


I am not stucked anywhere but I just wanna know why this code behave in this way?


If I remove "return"
than at the console I am getting six rows instead of five what I would've gotten if there were not a return command?


def print_board(board):
    for row in board:
        print " ".join(row)
    return " ".join(row)

what is the difference between this and the following?
def print_board(board):
    for row in board:
        print " ".join(row)
    

Replace this line with your code.


#2

The above line does not belong in the print_board function. Why? Because the function is a doer and has no return value expected by the calling scope. Its only role in the program is to draw the board, given a data structure.


#3

Thank you I think i am getting it but will you please elaborate it more


#4

Because the function is a doer and has no return value expected by the calling scope.

print_board()

There is no variable to receive a return value from the function, so there should be no return value sent back. Hence, we don't need a return statement in that function.

Functions come in many flavors. Some are... getters whose role is to retrieve data; setters whose role is to set (create or update) data; vetters whose role is to vet data (validate); netters whose role is to compute and return results given the data; and finally, fetters whose role is trivial, usually output. Most of these names I've made up, but the general role distinctions are there.

print_board() is a fetter by my nomenclature. No return value.


#5

thank you very much ....................................


#6

Disclaimer:

I make no direct connection to the true meaning of the word 'fetter'. But in a sense, the function is chained to output the object sends it. A bit crude, I'd admit. Didn't see this idiom until I dug in a bit. Not my intention to cross any lines.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.