I have python variables as given below.
global a,b,c
i want to initialize all these variables with different values in a single statement.
is it possible?
a=b=c=uuid.uuid1() //should return different values for a,b and c
Call uuid.uuid1()
three times:
a, b, c = uuid.uuid1(), uuid.uuid1(), uuid.uuid1()
You could make that a loop, but for 3 fixed items, why bother? Moreover, for an unpacking assignment like this with just 2 or 3 elements, the CPython compiler optimizes the bytecode.
If you use a loop anyway (if you have a few more targets to assign to), use a generator expression and avoid creating a list object:
a, b, c, d, e, f, g, h = (uuid.uuid1() for _ in xrange(8))
You can do that using a generator as:
a,b,c = (uuid.uuid1() for _ in range(3))
It will be particularly useful when you have lots of variables to assign data to.
a,b,c = (randint(1,10) for _ in range(3))
>>> print a,b,c
7 2 9