Sobes.tech
Intern

What type of data can be a value in a dictionary?

sobes.tech AI

Answer from AI

In a Python dictionary, a value can be any data type:

  • Numeric types (int, float, complex)
  • Sequences (str, list, tuple)
  • Sets (set, frozenset)
  • Boolean values (bool)
  • Empty value (None)
  • Other dictionaries (dict)
  • User-defined objects (class instances)
  • Functions and methods
# Examples of different data types as dictionary values
my_dict = {
    "integer_value": 10,
    "float_value": 3.14,
    "string_value": "hello",
    "list_value": [1, 2, 3],
    "tuple_value": (4, 5),
    "set_value": {"a", "b"},
    "bool_value": True,
    "none_value": None,
    "nested_dict": {"key": "value"},
    "object_value": object(), // Class instance
    "function_value": lambda x: x * 2 // Lambda function
}