+ 2
I don't understand this simple code
d=['a','b','c'] a,b,c=d d=c,b,a print(d) Output : ('c', 'b', 'a') Thanks!
2 Answers
+ 10
1. d = ['a','b','c']
=> d is a list with three values => a,b and c (all are strings)
2. a,b,c = d
=> We declare three variables a,b, and c which takes the first second and third values of the list d respectively.... The values of these variables are :-
a = 'a'
b= 'b'
c = 'c'
3. d = c,b,a
=> The list d (which was previously ['a','b','c'] ) now has the values of variables c,b,a ...
First element of d is now variable c (which is 'c')
Second is b ('b') and third is variable is c ('c').
The list is now reversed.
4. print(d)
Now print the list d.
+ 7
a = takes first element from list and that is 'a', b seond and that is 'b' and c third, 'c'. Then list takes that three values just in descending order. This is same with print(d[::-1])