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

Python Lists


Python Tutorial » Python Lists

Lists are very similar to arrays in Python. They can contain any type of variable, and many variables as you wish, or is used to store multiple items in a single variable
Lists are created using items between square brackets.

Example: Create Python List:
my_list = ["George", "John", "Chris", "Mary"]
print(my_list)

Output:
['George', 'John', 'Chris', 'Mary']


Accessing Values in Lists - examples


To access values in lists, use the square brackets

Example:
my_list1 = ['instructors', 'variable', 2020, 2021];
my_list2 = [6, 7, 8, 9, 10, 11, 12 ];
print "my_list1[0]: ", my_list1[0]
print "my_list2[2:5]: ", my_list2[2:5]
Output:
my_list1[0]: instructors
my_list2[2:5]: [8, 9, 10]


Allow Duplicates


In Python lists can have elements with the same value.

Example: allow duplicate values.
my_list = ["John", "Anna-Maria", "Chris", "Tom", "John"]
print(my_list)
Output:
['John', 'Anna-Maria', 'Chris', 'Tom', 'John']

List Items


Elements can be of any data type.

Example:
my_list1 = ["John", "Bann-Ann", "Jose"]
my_list2 = [12, 51, 72, 93, 36]
my_list3 = [False, True, False]

print(my_list1)
print(my_list2)
print(my_list3)
Output:
['John', 'Bann-Ann', 'Jose']
[12, 51, 72, 93, 36]
[False, True, False]




Python lists append, index, pop, length, comprehension, function, to string, count, find, methods
Python Lists - 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.