AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

Python Arrays


Python Tutorial » Python Arrays

Arrays are used to store multiple values in one single variable:

Example: We create an array containing names
names = ["John", "Chris", "Tom", "James", "Mason", "Jackson"]

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
numbers = ["34", "45", "04", "1245", "78"]
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:
numbers = ["34", "45", "04", "1245", "78"]
array_lentgh = len(numbers)
print(array_lentgh)
Output:
5


Looping Array Elements - example

We use "for in" (without quotes) loop to loop through all the elements of an array.

Example:
numbers = ["34", "45", "04", "1245", "78"]

for y in numbers:
  print(y)
Output:
34
45
04
1245
78


Adding Array Elements

We use append() method

Example:
numbers = ["34", "45", "04", "1245", "78"]
numbers.append("010101")
print(numbers)
Output:
['34', '45', '04', '1245', '78', '010101']


Removing Array Elements
We use the pop() method

Example: Syntax Error:
numbers = ["34", "45", "04", "1245", "78"]
numbers.pop(2)
print(numbers)
Output:
['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
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news 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
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news 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
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


CSS background color - opacity, gradient...
CSS flex - display: flex - CSS Flexbox L...
CSS border padding...
HTML text center horizontally and vertic...
HTML text input <input type="text"&g...
HTML link color...
How to Link CSS to HTML, external file n...
HTML link - hyperlink...
jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...