16
Phase 4 - Level 1: Basic Arrays
Chapter 16 • Beginner
60 min
Phase 4 - Level 1: Basic Arrays
Introduction to Arrays
Arrays (lists in Python) allow you to store multiple values in a single variable. They are essential for working with collections of data.
Array Basics
Creating Arrays
python.js
arr = [1, 2, 3, 4, 5] # List of numbers
arr = [] # Empty list
Accessing Elements
- Index starts at 0
arr[0]- first elementarr[-1]- last element
Common Operations
len(arr)- lengtharr.append(x)- add elementarr[i]- access element at index i
Key Concepts
- Indexing: Access elements by position (0-based)
- Iteration: Loop through all elements
- Accumulation: Sum, count, find max/min
- Input/Output: Read and display arrays
Common Patterns
- Input n elements into array
- Sum all elements
- Find maximum/minimum
- Count elements meeting condition
Hands-on Examples
Input and Print Array
# Take n as input
n = int(input("Enter number of elements: "))
# Input array
arr = []
print("Enter elements:")
for i in range(n):
element = int(input())
arr.append(element)
# Print array
print("Array elements:")
for element in arr:
print(element, end=" ")
print()Use a loop to input n elements and append to list. Then iterate through list to print all elements.
Related Tutorials
🔗Related Content
- 💻
Phase 4 - Practice Problems
Practice Phase 4 concepts with hands-on coding problems
- 📝
Phase 4 - Quiz
Test your Phase 4 understanding with assessment questions
- ➡️
Phase 5 - Get Started
Continue to Phase 5 after mastering Phase 4
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum