社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python中的board[x,y]`和board[x][y]`有区别吗?

Broski-AC • 5 年前 • 2063 次点击  

我正在通过一个 tutorial on GeekforGeeks website 注意到他们正在使用 board[x,y] ,这是我从未见过的。我不认为这行得通,但当我运行程序时,一切都按预期进行。

我试着用上面概述的方法运行一个更小的代码示例,而不是我更熟悉的方法( board[x][y] )但是当我运行代码时 TypeError: list indices must be integers or slices, not tuple

我的代码:

board = [[1,1,1], [1,2,2], [1,2,2]]
win = 'True'

if board[1][1] == 2:
    win = 'True by normal standards'
    print(win)
if board[1, 1] == 2:
    win = 'True by weird standards'
    print(win)

print(win)

他们的代码:

def row_win(board, player): 
    for x in range(len(board)): 
        win = True

        for y in range(len(board)): 
            if board[x, y] != player: 
                win = False
                continue

        if win == True: 
            return(win) 
    return(win) 

有人能解释一下为什么吗 董事会 有效,到底发生了什么?我以前从来没有见过这个,除了创建列表,也没有从概念上理解它。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39499
 
2063 次点击  
文章 [ 6 ]  |  最新文章 5 年前