w3resource

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?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Big Number Readability:

you can separate zeros with underscore (_)

print(2_000_000)
print(2_000_000 +1)

Output:

2000000
2000001