Python 3
Python 3
double quotes are used for string representation and single quotes are used for regular
expressions, dict keys . Hence both single quote and double quotes depict string in
python but it’s sometimes our need to use one type over the other.
Mutable Objects-These can be changed after their creation. We can modify the contents of
these objects without changing their identity. ex-list, sets, dict.
Immutable objects-These cannot be changed after their creation. Any change to these
objects results in the creation of a new object. Ex-string, tuple, integer
List is ordered collection elements, enclosed in square brackets [ ] and mutable means can
be changed after creation while tuple is ordered collection elements ,enclosed in
parenthesis ( ) and immutable means can not changed after creation.
4. What are the difference between a set and list in terms of Functionality and use cases?
List-Ordered collection of elements. duplicates allowed. Mutable, and allows indexing and
slicing.
5. How does a dictionary differ from a list in term of data storage and retrieval?
List-is ordered, index-based, and mutable, suitable for collections where order matters and
elements can be repeated.
Dictionary-is key-based, offering fast lookups and ideal for situations where each element
has a unique identifier (key).