Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary question
#6
Thanks for all the response!

The below looks interesting, could someone explain the code?

[python]
def car(make, model, style, year, color):
    return {'make':make, 'model':model, 'style':style, 'year':year, 'color':color}
 
cars = {'fun car':car('Chevrolet', 'Corvette', 'coupe', 2020, 'red'),
        'work car':car('Ford', 'F150', 'truck', 1990, 'rust'),
        'dad van':car('Chrysler', 'Pacifica', 'minivan', 2015, 'white')}
 
for label, car in cars.items():
    print(label, '\n', car, '\n')
[/python]
Reply


Messages In This Thread
Dictionary question - by kam_uk - Nov-21-2020, 02:07 AM
RE: Dictionary question - by buran - Nov-21-2020, 07:26 AM
RE: Dictionary question - by kam_uk - Nov-21-2020, 12:33 PM
RE: Dictionary question - by perfringo - Nov-21-2020, 05:19 PM
RE: Dictionary question - by deanhystad - Nov-21-2020, 03:01 PM
RE: Dictionary question - by kam_uk - Nov-21-2020, 08:18 PM
RE: Dictionary question - by deanhystad - Nov-21-2020, 08:42 PM
RE: Dictionary question - by ndc85430 - Nov-22-2020, 05:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  dictionary question stereokim123 2 38,208 Apr-01-2021, 10:23 PM
Last Post: stereokim123

Forum Jump:

User Panel Messages

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