4.8k views
2 votes
The items() method returns a list of all the key-value pairs in a dictionary as tuples.

Question 6 options:
True
False

User Jmkgreen
by
7.3k points

1 Answer

6 votes

Answer:

The statement "The items() method returns a list of all the key-value pairs in a dictionary as tuples" is true.

Step-by-step explanation:

The items() method in Python is used to return a list of all the key-value pairs present in a dictionary. Each key-value pair is returned as a tuple, where the key is the first element and the value is the second element of the tuple.

For example, consider the following dictionary:

```python

my_dict = {'name': 'John', 'age': 25, 'country': 'USA'}

```

If we call the items() method on this dictionary like this:

```python

items = my_dict.items()

```

The variable `items` will contain a list of tuples representing the key-value pairs:

```python

[('name', 'John'), ('age', 25), ('country', 'USA')]

```

Each tuple in the list corresponds to a key-value pair from the dictionary.

Therefore, the statement is true: the items() method returns a list of all the key-value pairs in a dictionary as tuples.

User Billmaya
by
7.4k points