gpt4 book ai didi

c++ - python 中等效的 C++ 嵌套打印

转载 作者:行者123 更新时间:2023-11-30 02:10:23 25 4
gpt4 key购买 nike

我试图在 python 中运行此 C++ 语句,但在将打印放入循环中时遇到问题。

for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
cout<<_3x3x3[i][j][k]<<" ";
}
}
//print here in python
cout<<endl;
}

在 python 中:

_3x3x3 = [[[0 for col in range(3)] for row in range(3)] for depth in range(3)]

for i in range(3):
for j in range(3):
for k in range(3):
_3x3x3[i][j][k] = 1

for col in _3x3x3:
print col
print
for row in _3x3x3:
print row
print
for depth in _3x3x3:
print depth
#I want to print this in the C++ style above
for i in range(3):
for j in range(3):
for k in range(3):
print _3x3x3[i][j][k]

最佳答案

for i in range(3):
for j in range(3):
for k in range(3):
# something here
print _3x3x3[i][j][k],
print

关于c++ - python 中等效的 C++ 嵌套打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4653507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com