0

Two confusions in this: a,b,*c = [x for x in range(1,5)]

a,b,*c = [x for x in range(1,5)] 1. What does that mean *c? I don't think it is a valid variable. 2. I know for x in range(5) But what does that mean x for x in range(5)?why they put a x in front of this loop.

28th Dec 2018, 1:50 PM
sky
sky - avatar
1 Respuesta
+ 2
1. Tuple Unpacking https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2485/?ref=app *c means taking the rest of variables In your example, range(1,5) is 1,2,3,4 a = 1 b = 2 *c = the rest so c = [3, 4] 2. List comprehension Just like writing a for loop but in one line https://www.sololearn.com/learn/Python/2454/ range() returns a generator, so you cannot use list unpacking directly, so use a for loop to take the values out.
28th Dec 2018, 2:04 PM
Gordon
Gordon - avatar