loader
INTRODUCTION TO LISTS IN PYTHON

LIst of contents:

  1. Lists
  2. List items
  3. Ordered
  4. Changeable
  5. Allow Duplicates
  6. List length
  7. List items (data type)
  8. type()
  9. The list() constructor
  10. Python collection (arrays)

LISTS

Python lists are one of the most flexible tools that you will use when you start programming. They let you store many items in one place, making it simple to organise and manage your data, you can read more on python website.

Example:

mylist = ["apple", "banana", "cherry"]

LIST ITEMS

list items are the individual elements that make up a list. A list is a built in data structure that allows you to store an ordered collection of items

ORDERED

it means that the elements in the list maintain a specific sequence based on the order in which they were added.

CHANGEABLE 

refers to the mutability of an object, meaning that the object's content can be modified after it has been created.

ALLOW DUPLICATES

it means that a list can contain multiple instances of the same value.

Examples:

lista = ["apple", "banana", "cherry", "apple", "cherry"]
print(lista)

LIST LENGTH

list length refers to the number of items or elements it contains. 

Example:

lista = ["apple", "banana", "cherry"]

print(len(lista))

LIST ITEMS (DATA TYPE)

refers to the types of elements that can be stored within a list. Python lists are versatile data structures that can hold items of different data types.

Example:

list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]

TYPE()

is used to determine the data type of an object, including the elements within a list.

Example:

mylist = ["apple", "banana", "cherry"]
print(type(mylist))

THE LIST() CONSTRUCTOR 

It is a built in function used to create a new list. It can take an iterable like a string, tuple, set, or another list as an argument and convert it into a list. If no argument is provided, it creates an empty list.

Example:

thislist = list(("apple", "banana", "cherry")) # note the double round-brackets
print(thislist)

PYTHON COLLECTION (ARRAYS)

  1. Lists:
    Lists are one of the most commonly used collection types. They are mutable, ordered, and can hold items of different data types.
  2. Tuples:
    Tuples are similar to lists but they are immutable or they cannot be changed after creation. They can also hold items of different data.

  3. SETS:Sets are unordered collections that do not allow duplicate elements.They are useful for membership testing and removing duplicates.
  4. DICTIONARY:Dictionary store key-value pairs and are unordered. Keys must be unique, while values can be of any data type.