Python List, Tuple & Dictionary

1. List

In Python, a “list” is a collection of values that are ordered and mutable (can be changed).

Here’s an example of a list of cars:

2. Tuple

A “tuple” is similar to a list in that it is a collection of values. However, tuples are ordered and immutable (cannot be changed). Tuples are defined using parentheses () instead of square brackets. Here’s an example of a tuple of cars:

3. Dictionary

A “dictionary” is a collection of key-value pairs, where each key is unique. Dictionaries are defined using curly braces {}. In the example below, each car name is the key and its corresponding value is a dictionary of specifications:

In this example, you can access the information about a specific car by using its name as a key:

List, Tuple & Dictionary example in one code:

here’s an example that demonstrates the usage of lists, tuples, and dictionaries in the context of a car:

When run, the code outputs:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top