Array
=============================
What is Array :
-> An array is a collection of elements (items). All elements must be of the same
data type.
Why use Array :
-> Used to store multiple values in a single variable, without declaring separate
variables.
Where use Array :
-> Used in loops, sorting, searching, and when you need to store a fixed-size list
of elements.
Example:
================
numbers = [10, 20, 30, 40, 50]
print(numbers[2]) # Output: 30
-> Array work with index number you have to pass index number.
Types of Arrays
========================
-> One-dimensional Array (1D)
-> Two-dimensional Array (2D)
-> Multi-dimensional Array
-> One-dimensional Array (1D) :
-> Single row or column of elements.
example:
arr = [1, 2, 3, 4]
print(arr[0]) # Output: 1 # pass index number
-> Two-dimensional Array (2D) :
-> Array of arrays (like a table or matrix). create array inside array.
example:
matrix = [[1, 2], [3, 4]]
print(matrix[1][0]) # Output: 3
-> Multi-dimensional Array :
-> More than two levels.
example:
arr3D = [ [ [1, 2], [3, 4] ], [ [5, 6], [7, 8] ] ]
print(arr3D[1][0][1]) # Output: 6
String Arrays
====================
-> array is collections of elements but it's strings types elements.
example:
names = ["A", "B", "C"]
print(names[1]) # Output: B