Python basics: dictionary

Dictionary type

A method also called a hash It is a set of key and value.

The caveat is to use {}.

city = {"Key 1": "Value 1", "Key 2": "Value 2"}

Extraction of dictionary

Call by specifying the key.

dic ={"book": "kokugo", "name": "yamada"}
print(dic["book"]) 
#output: kokugo

Overwrite and add

Overwrite


dic ={"book": "kokugo", "name": "yamada"}
dic["book"] = "sugaku"
print(dic) 

#output: {"book": "suugaku", "name": "yamada"}

add to


dic ={"book": "kokugo", "name": "yamada"}
dic["seibetu"] = "men"

print(dic) 
#output: {"book": "kokugo", "name": "yamada", "seibetu": "men"}

Delete element

Delete


dic = {"book": "kokugo", "name": "yamada", "seibetu": "men"}
del dic["book"] 
#Delete the specified element
print(dic) 
#output: {"name": "yamada", "seibetu": "men"}

Recommended Posts

Python basics: dictionary
Python basics ⑤
Python basics
Python basics ④
Python basics ③
Python basics
Python dictionary
Python basics
Python basics
Python basics ③
Python basics ②
[Python] dictionary
Python basics ②
Python dictionary
[Python] Memo dictionary
Python basics memorandum
#Python basics (#matplotlib)
[Python] Dictionary (hash)
Python CGI basics
Basics of Python ①
Basics of python ①
Python slice basics
#Python basics (scope)
#Python basics (#Numpy 1/2)
#Python basics (#Numpy 2/2)
#Python basics (functions)
Python array basics
Python profiling basics
Python #Numpy basics
Python basics: functions
#Python basics (class)
Python basics summary
Python Basic Course (7 Dictionary)
Python basics ② for statement
Python: Unsupervised Learning: Basics
Basics of Python scraping basics
Python basics 8 numpy test
Errbot: Python chatbot basics
#Python DeepLearning Basics (Mathematics 1/4)
Python3 List / dictionary memo
Python basics: Socket, Dnspython
Python Dictionary Beginner's Guide
# 4 [python] Basics of functions
Basics of python: Output
Python list, for statement, dictionary
Create a dictionary in Python
Python
python: Basics of using scikit-learn ①
Python> dictionary / collections> defaultdict () / Counter ()
Python basics: conditions and iterations
Avoid KeyError in python dictionary
Paiza Python Primer 4: List Basics
Basics of Python × GIS (Part 1)
Python> dictionary> get ()> optional value
Basics of Python x GIS (Part 3)
Paiza Python Primer 5: Basics of Dictionaries
Notes on Python and dictionary types
SNS Python basics made with Flask
Expansion by argument of python dictionary
Replace dictionary value with Python> update ()
Getting Started with Python Basics of Python