Hi, im trying to figure out how to call a function's variable
from here

def legal_moves(board):
    moves = []
    for square in range(DINNER):
        if board [square] == SPACE:
            moves.append(square)
    return moves

I want to take the variable moves and use it for main

How would I do that?

Recommended Answers

All 2 Replies

with out using
legal_moves(board)
in main

With

global moves

or by adding moves as one more parameter, which will change the caller's variable as list is mutable.

Or by using legal_moves.moves instead of moves, but that is quite special way, which is not generally practiced.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.