list all data structures and built-in functions in python
- User
list all data structures and built-in functions in python
Assistant
Data Structures in Python
Python offers several built-in data structures that efficiently store and organize data:
1. Lists:
- Ordered, mutable collections that can hold elements of different data types.
- Defined using square brackets
[]. - Examples:
[1, 2, 3],["apple", "banana", "cherry"],[1, "hello", True].
2. Tuples:
- Ordered, immutable collections that hold elements of different data types.
- Defined using parentheses
(). - Once created, elements cannot be changed.
- Examples:
(1, 2, 3),("apple", "banana", "cherry"),(1, "hello", True).
3. Sets:
- Unordered, mutable collections of unique elements.
- Defined using curly braces
{}or theset()constructor. - Elements must be immutable (e.g., numbers, strings).
- Examples:
{1, 2, 3},{"apple", "banana", "cherry"},set([1, 2, 3]).
4. Dictionaries:
- Unordered collections of key-value pairs.
- Keys must be immutable (e.g., numbers, strings).
- Defined using curly braces
{}or thedict()constructor. - Examples:
{"name": "John", "age": 30},{"fruit": "apple", "color": "red"},dict(name="Jane", age=25).
5. Strings:
- Ordered, immutable sequences of characters.
- Defined using single quotes
' 'or double quotes" ". - Examples:
'Hello',"World","Python".
6. Bytes:
- Immutable sequences of bytes, often used for binary data.
- Defined using the
bytes()constructor orb' 'prefix. - Examples:
bytes([1, 2, 3]),b'hello'.
7. Bytearray:
- Mutable sequences of bytes, similar to
bytes. - Defined using the
bytearray()constructor. - Examples: , .