User Tools

Site Tools


clubs:python_club:python_club_dictionary
Home | clubs :: cloud club :: python_club :: 3D-Printing | projects :: Proxmox | Kubernetes | scripting | utilities | games

About the Club

Python Club Topics - Dictionaries

Dictionary

  1. Often shortened to “dict”
  2. Multiple values under 1 variable name
  3. Used to store collections of data
  4. Data stored in key & value pairs
  5. Ordered ( starting in Python 3.7 )
  6. Keys CANNOT be duplicated
  7. Created using curley braces ( eg. { } )
  8. key pairs CAN be changed

Dictionary Example

  1. Create a dictionary
    my_car = {
      "brand": "Ford",
      "model": "Focus",
      "year": 2010
    }
    print(my_car)
    print("This brand ==> " + my_car["brand"])
  2. Use the len() function
    my_car = {
      "brand": "Ford",
      "model": "Focus",
      "year": 2010
    }
    print(len(my_car))
  3. Change the value under a key
    my_car = { 
      "brand": "Ford",
      "model": "Focus",
      "year": 2010
    }
    my_car['model'] = "Mustang"
    print(my_car)
     
clubs/python_club/python_club_dictionary.txt · Last modified: by 127.0.0.1