Python Python Collections (2016, retired 2019) Dungeon Game Movement

Andrew McLane
Andrew McLane
3,385 Points

What is the ' '.join used for in the line print ("You can move {}".format(", ".join(get_moves(player))))

print ("You can move {}".format(", ".join(get_moves(player))))

I don't understand why or what we're joining.

1 Answer

Steven Parker
Steven Parker
177,536 Points

The "get_moves" function returns a list, and "join" converts a list into a string.

The string then becomes the argument to "format", which is the reason for performing the "join".