等效 C++ python 中的嵌套打印
我正在尝试在 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]
I'm trying to run this C++ statement in python and I'm having trouble placing the print in the loop.
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;
}
in 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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了多样性和面向未来:
此代码与 C++ 代码之间的区别在于,它不会在每行末尾、换行符之前输出空格。不过,这可能是一件好事。
For variety, and future-proofing:
The difference between this and the C++ code is that this doesn't output a space at the end of each line, before the newline. That's probably a good thing, though.