Array¶
The array data type is used to store multiple values. An array can hold elements of different types. An array can store any kind of elements — from integers to strings to functions.
Examples¶
More on the built-in functions can be found in the Built-in Function section
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
Array Operations¶
Append to Array¶
There are two ways to append a value to an array.
The first one is to use the + operator, and the second way is to use the built-in function append()
1 2 3 | |
3 to the array using the + operator,
then appending "fourth" to the array using the built-in function append()
Remove from Array¶
There are two ways to remove a value from an array.
The first one is to use the - operator, and the second way is to use the built-in function pop()
1 2 3 | |
- operator,
then removing the 0th element from the array using the built-in function append().
These actions result in an empty array
Extend Array¶
There are two ways to extend an array with another array.
The first one is to use the * operator, and the second way is to use the built-in function extend()
1 2 3 | |
[3, "fourth"] using the + operator,
then the array with [5, "sixth"] using the built-in function append()
Get element from array¶
Use the / operator to get a specific element from the array
1 2 | |
selected.
This results in "second"
Get size of the array¶
Use the built-in function length() to get the size of the array
1 2 | |
size is 2 because there are two elements in arr