Python Arrays
Python Tutorial » Python Arrays
Arrays are used to store multiple values in one single variable:
Example: We create an array containing names
Output:
['John', 'Chris', 'Tom', 'James', 'Mason', 'Jackson']
names = ["John", "Chris", "Tom", "James", "Mason", "Jackson"]
print(names)
print(names)
Output:
['John', 'Chris', 'Tom', 'James', 'Mason', 'Jackson']
Access an element of an Array
If you have a list of items as: numbers, names, cars for example
Example: acces an element from list
Output:
04
numbers = ["34", "45", "04", "1245", "78"]
my_number = numbers[2]
print(my_number)
my_number = numbers[2]
print(my_number)
Output:
04
Length of an Array - example
To get length use the len() method to return length of an array
Example:
5
numbers = ["34", "45", "04", "1245", "78"]
array_lentgh = len(numbers)
print(array_lentgh)
Output: array_lentgh = len(numbers)
print(array_lentgh)
5
Looping Array Elements - example
We use "for in" (without quotes) loop to loop through all the elements of an array.
Example:
34
45
04
1245
78
numbers = ["34", "45", "04", "1245", "78"]
for y in numbers:
print(y)
Output:for y in numbers:
print(y)
34
45
04
1245
78
Adding Array Elements
We use append() method
Example:
['34', '45', '04', '1245', '78', '010101']
numbers = ["34", "45", "04", "1245", "78"]
numbers.append("010101")
print(numbers)
Output:numbers.append("010101")
print(numbers)
['34', '45', '04', '1245', '78', '010101']
Removing Array Elements
We use the pop() method
Example: Syntax Error:
['34', '45', '1245', '78']
numbers = ["34", "45", "04", "1245", "78"]
numbers.pop(2)
print(numbers)
Output:numbers.pop(2)
print(numbers)
['34', '45', '1245', '78']
python arrays length, append, index, of objects, declaration, vs list, of arrays, of strings, slice, push
Python Arrays - python
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.