What is the difference between len() and size in Python?
What is the difference between len() and size in Python?
What is the difference between len() and size in Python?
solveurit24@gmail.com Changed status to publish February 13, 2025
len(): Returns the number of elements in an object (e.g., a list, string, or dictionary).size(e.g.,array.sizein NumPy orsys.getsizeof()): Returns the memory size of an object.
Example:
import numpy as np
my_list = [1, 2, 3]
my_array = np.array(my_list)
print(len(my_list)) # Output: 3
print(my_array.size) # Output: 3
solveurit24@gmail.com Changed status to publish February 13, 2025