How to print a dictionary's key?

前端 未结 20 827
眼角桃花
眼角桃花 2020-11-27 09:22

I would like to print a specific Python dictionary key:

mydic = {}
mydic[\'key_name\'] = \'value_name\'

Now I can check if mydic.has_

20条回答
  •  Happy的楠姐
    2020-11-27 09:57

    To access the data, you'll need to do this:

    foo = {
        "foo0": "bar0",
        "foo1": "bar1",
        "foo2": "bar2",
        "foo3": "bar3"
    }
    for bar in foo:
      print(bar)
    

    Or, to access the value you just call it from the key: foo[bar]

提交回复
热议问题