Question-138: When you run below code, it would
temps = [[1 for i in range(3)] for j in range(5)]
print(temps)
- Generate 2-dimensional list of size 5X3
- Get all Questions and Answer from here
- You need to have paid subscription to access all questions
- Thanks for considering Python Certification Material
Answer: A
Exp:
List comprehension
Below code will generate 2-dimensional list of size 5X3
- 5 rows
- Each row has 3 elements in it.
- Value of each element is 1
temps = [[1 for i in range(3)] for j in range(5)] print(temps) |
Below code will generate 3 dimensional list of size 5X3X2
- There is no limit for dimension you can create for a matrix.
temps = [[[1 for i in range(3)] for j in range(5)] for k in range(2)] print(temps) |
You can access to full explanation to question and answer from this page.