In Python 3.10, you can get the size of an array using the len() function. Here are some examples:
Example 1: Get the size of an integer array
array = [1, 2, 3, 4, 5]
size = len(array)
print("The size of the array is", size)
Output:
The size of the array is 5
Example 2: Get the size of a string array
array = ["apple", "banana", "cherry"]
size = len(array)
print("The size of the array is", size)
Output:
The size of the array is 3
Example 3: Get the size of a 2D array
array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
size = len(array)
print("The size of the array is", size)
Output:
The size of the array is 3
In this example, the size of the array is the number of rows in the 2D array.
Example 4: Get the size of a 3D array
array = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
size = len(array)
print("The size of the array is", size)
Output:
The size of the array is 2
In this example, the size of the array is the number of 2D arrays in the 3D array.