POSO
@POSO

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

python の配列について

解決したいこと

配列が発生しない理由が知りたい

発生している問題・エラー

member_dict = {
  '001': 'ujin'
}

member_name = member_dict['001']
print(f'name is {member_name}.')

member_dict['002'] = 'lee'#追加
new_member_name = member_dict['002']
print(f'new name is {new_member_name}.')

member_dict['001'] = 'bang'#上書き
overwritten_name = member_dict['001']
print(f'next name is {overwritten_name}.')

for key in member_dict:
  value = member_dict[key]
print(f'number{key} name is {value}.')
number = len(member_dict)
print(f'member is {number}')

これの結果が

name is ujin.
new name is lee.
next name is bang.
number002 name is lee.
member is 2

となり、配列が表示されない

自分で試したこと

誤字脱字の確認

0

2Answer

配列とは「発生」するものではないですが、それはともかく…
具体的に何がどうなることを期待したのですか?

0Like

Comments

  1. @POSO

    Questioner

    number1、number2が両方出力できるようにしたいです

期待する出力結果を書くといいですよ。
printのインデントがずれていると回答がついていた気がするけど、取り下げてしまったのかな?

member_dict = {
  '001': 'ujin'
}

member_name = member_dict['001']
print(f'name is {member_name}.')

member_dict['002'] = 'lee'#追加
new_member_name = member_dict['002']
print(f'new name is {new_member_name}.')

member_dict['001'] = 'bang'#上書き
overwritten_name = member_dict['001']
print(f'next name is {overwritten_name}.')

for key in member_dict:
  value = member_dict[key]
  print(f'number{key} name is {value}.')
number = len(member_dict)
print(f'member is {number}')

key と value を一度に取り出す方法もあります。

for key, value in member_dict.items():
  print(f'number{key} name is {value}.')
0Like

Comments

  1. @POSO

    Questioner

    ありがとうございます

Your answer might help someone💌