How to create an array in Python
arr = [10, 20, 30, 40, 50]
Accessing elements of array using indexing
arr = [10, 20, 30, 40, 50]
print(arr[0])
print(arr[1])
print(arr[2])
Ans:
10
20
30
Accessing elements of array using negative indexing
arr = [10, 20, 30, 40, 50]
print(arr[-1])
print(arr[-2])
Ans.
50
40
Find length of an array using len()
brands = ["Coke", "Apple", "Google", "Microsoft", "Toyota"]
num_brands = len(brands)
print(num_brands) Ans: 5
No comments:
Post a Comment