Lesson 19 of 55
9 mins readPython Array Fundamentals: Sigil (@) & Indexing
In Plain English
Perl arrays are ordered collections of scalars denoted by the `@` sigil. Individual elements are scalars, so accessing an element changes the sigil to `$array[index]`.
Deep Dive: How It Works
Sigil Transition: Whole array is `@items`, but a single item is `$items[0]` (dollar sign for single scalar).
Zero-Indexed: First element is at index 0.
Negative Indices: `$items[-1]` returns the last element, `$items[-2]` the second to last.
Array Size: `scalar(@items)` returns the count; `$#items` returns the highest valid index.
Core Rules to Remember

@ for All, $ for One: Use `@array` for the whole array and `$array[$i]` for a single element.

Last Index ($#array): `$#array` is `scalar(@array) - 1`.
Live Interactive Example
Hit Run Code to see it liveCreating and Querying Arrays
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Output Console
Click "Run Code" to view the rendered output.
How it works: scalar(@tools) returned 4 elements; $#tools returned index 3.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Access Array Elements
Declare `my @langs = ("C", "Perl", "Go");`
Print `"Primary: $langs[1], Total: " . scalar(@langs) . "\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.