cars = [1, 2 ,3]
print(len(cars))
>>3
print(len("hello"))
>>5The len() function returns the number of items in an object.
When the object is a string, the len() function returns the number of characters in the string.
numbers = [10, 20, 30, 40]
for i in range(len(numbers)):
print(i, numbers[i])output
0 10
1 20
2 30
3 40List:
dynamic
- size
- data type
Array:
fixed
- size
- datatype
Array do not append or pop
analogy: array is like calling up a restaurant for 5 adult chair and 5 baby chair. If 5 adults turn up, not enough seat for everyone.