DEV Community

Msaghu
Msaghu

Posted on • Updated on

Day 4; Basic Python Collections(Python 30 Day challenge)

1. Lists

Lists are created by having characters inside square brackets, separated by commas, with each value inside quotation marks
The code below also shows how to access items within a list
List rules

  1. Can only add a list to another list
  2. Can only use these *, + operators Lists and how to access them

Adding items to a list

using the .append() method

adding items to a list using the append method

using the + operator

adding items to a list using the + operator

using the .extend() method

adding items to a list using the extend method

using the .insert() method

adding items to a list using the insert method

Removing items from a list

using the .remove() method

Image description

using the del

Image description

using the .pop() method

Image description

using the .clear() method

Image description

2. Tuples

Tuples are immutable i.e once created they cannot be changed
But they can be nested inside lists, where they are easily accessible using their index
Image description

3. Maps/Dictionary

A combination of tuples and lists that can be accessed with a key and a value.
Contains curly brackets , and the key-value pair is separated with a colon, and separated with single quotes
Cannot join maps with the '+' operator

4. Exercise day 4 code

Image description

Top comments (0)