Is there a way to assign multiple variables a same value or attribute?

烂漫一生 提交于 2021-02-07 19:58:53

问题


In Python, is there a way to make

a, b, c, d, e = 'dog'

so that

a = 'dog'

b = 'dog'

#etc.

or

a, b, c, d, e = list()

so that

type(a through e) 

returns

type 'list'

回答1:


This has already been answered here: Set multiple variables to the same value in Javascript

in python it would be:

a = b = c = d = e = 'dog'

its the same in javascript but with 'var' at the beginning:

var a = b = c = d = e = 'dog'



回答2:


In c# in would be as simple as declaring the variables and then setting them all equal.

string a,b,c,d;

a = b = c = d = "dog";


来源:https://stackoverflow.com/questions/28308920/is-there-a-way-to-assign-multiple-variables-a-same-value-or-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!