本文介绍了使用键值和没有对应值的python中的字典初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以在python中用键初始化字典,但没有相应的值,直到我设置它们.如:

I was wondering if there was a way to initialize a dictionary in python with keys but no corresponding values until I set them. Such as:

Definition = {'apple': , 'ball': }

然后我可以设置它们:

Definition[key] = something

我只想初始化键,但是直到以后必须设置它们时,我才知道相应的值.基本上,我知道要添加找到值的键.谢谢.

I only want to initialize keys but I don't know the corresponding values until I have to set them later. Basically I know what keys I want to add the values as they are found. Thanks.

推荐答案

您可以将它们初始化为None.

You could initialize them to None.

这篇关于使用键值和没有对应值的python中的字典初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 11:04