Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing Dictionaries
#1
Is this code doing what it is supposed to do?

alien_0 = {}

alien_0['color'] = 'green'
alien_0['points'] = 5

print(alien_0)
Output:
{'color': 'green', 'points': 5}
I thought it would output just the word green and the number 5.
Reply
#2
yes, it is. alien_0 is a dict, i.e. it has key:value pairs. There are other data structures like list, tuple, etc.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020