Skip to content
Discussion options

You must be logged in to vote

Answer

Python provides four commonly used built-in data structures, each designed for different purposes.

Feature List Tuple Set Dictionary
Mutable Yes No Yes Yes
Ordered Yes Yes No Yes
Duplicates Allowed Allowed Not allowed Keys must be unique
Access Index Index Membership / iteration Key
Syntax [] () {1, 2} {key: value}

1. List

Lists are useful when maintaining an ordered collection of items that may change.

languages = ["Python", "JavaScript", "C++"]

languages.append("Rust")

print(languages)

2. Tuple

Tuples are suitable for storing fixed collections of values.

coordinates = (24.8607, 67.0011)

print(coordinates[0])

3. Set

Sets are useful for storing unique values an…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by adil12hassan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants