StepsEasy
Python Lists - Example
Run
Reset
Destroy & Close
← Back to lesson
Code Editor
python
# Creating lists fruits = ['apple', 'banana', 'cherry'] # List operations fruits.append('date') fruits.insert(1, 'avocado') fruits.remove('banana') # Slicing first_two = fruits[:2] last_two = fruits[-2:] # List comprehension squares = [x**2 for x in range(10)] even = [x for x in range(20) if x % 2 == 0] print(fruits) # ['apple', 'avocado', 'cherry', 'date'] print(squares) # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
Result
Click "Run" to execute the code...
Loading runtime...
Ready
PYTHON | In-Browser Execution