如何在python中将字典的长度返回给变量?

时间:2018-03-04 21:52:09

标签: python dictionary

如何在python中将字典的长度返回给变量?

3 个答案:

答案 0 :(得分:1)

只需使用len():

dic = {'val1':0,'val2':0,'val3':0}
length = len(dic)

答案 1 :(得分:0)

ExecutorService service = new ThreadPoolExecutor(8, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());

获取字典中的键数。相当于my_var = len(my_dict)

答案 2 :(得分:0)

my_dict = {'a':1,'b':2,'c':3}

var = len(dict)