w3resource
Python Exercises

Python: Generate a 3D array

Python List: Exercise - 13 with Solution

Write a Python program to generate a 3*4*6 3D array whose each element is *.

Sample Solution:-

Python Code:

array = [[ ['*' for col in range(6)] for col in range(4)] for row in range(3)]
print(array)

Sample Output:

[[['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '
*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'
, '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*'
, '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']]]

Pictorial Presentation:

Python List: Generate a 3D array

Flowchart:

Flowchart: Generate a 3D array

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to print a specified list after removing the 0th, 4th and 5th elements.
Next: Write a Python program to print the numbers of a specified list after removing even numbers from it.

What is the difficulty level of this exercise?