Created
May 8, 2019 20:26
-
-
Save ItsCosmas/31a9d635bab2bfcc35633d3c807add59 to your computer and use it in GitHub Desktop.
Dictionaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ages = {"Cozy": 21, "Mark": 22, "Dan": 25} | |
primary = { | |
"red": [255, 0, 0], | |
"green": [0, 255, 0], | |
"blue": [0, 0, 255] | |
} | |
print(primary["red"]) | |
print(ages["Cozy"]) | |
# Only Immutable objects can be used as keys to dictionaries | |
# Dictionaries and Lists are mutable and cannot be used as keys in a dictionary | |
# DICTIONARY FUNCTIONS | |
squares = {1: 1, 2: 4, 3: "Error", 4: 16, } | |
print(squares) | |
squares[3] = 9 | |
squares[8] = 64 | |
print(squares) | |
print(4 in squares) | |
print(4 not in squares) | |
print(squares.get(9, "Not in Squares")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment