私は Python で辞書について学んでいて、簡単なプログラムを作成しました。
# Create an empty dictionary called d1
d1 = {}
# Print dictionary and length
def dixnary():
print "Dictionary contents : "
print d1
print "Length = ", len(d1)
# Add items to dictionary
d1["to"] = "two"
d1["for"] = "four"
print "Dictionary contents :"
print d1
print "Length =" , len(d1)
# Print dictionary and length
print dixnary()
print
コマンドを使用したときと関数を使用したときの結果に違いがありdixnary
ます。
print
コマンドを使用すると、結果が得られます。
辞書の内容:
<'to':'two','for:'four'>
長さ = 2
関数を使用するとdixnary
、結果が得られます。
辞書の内容:
<'to':'two','for:'four'>
長さ = 2
なし
None
最終行の に注意してください。関数を使用すると、これNone
が追加されますdixnary
。どうしてこれなの?