'Why does this print?

I'm trying to create a text based game in Python. I made a dictionary of rooms.

Room_dictionary

afterwards I created a variable called starting_room. I then assigned starting room to 'Meadow'...

starting_room = rooms['Meadow']

Then I run the program and it printed off the dictionary of starting room without me initiating a print statement.

output: {'East': 'Town'}

My question is; why did it print? As well as why the dictionary and not just the word meadow?

I apologize if this is a dupe question.



Solution 1:[1]

The variable "rooms" contains a dictionary (key, value pairs). So, by assigning "rooms['Meadow']" to "starting_room" all you're doing is picking the value that the key 'Meadow' has i.e., {'East': 'Town'}.

If you want the whole dictionary and its key, values, you can try:

for key, value in rooms:
    print(f"{key} -> {value}")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nowshad Ruhani Chowdhury