84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
a=['one','two'] for p,q in a: print p,q
出错
a=[['one','tow']] for p,q in a: print p,q
这样就可以第一种我一直就认为是这样的:a的one,two分别赋值给p,q。不然得怎么理解?
人生最曼妙的风景,竟是内心的淡定与从容!
In Python, a for loop runs through each element in a list (or generator). So the correct form of the first loop is:
for x in a: print(x)
In addition, in Python we can write:
x, y = (1, 2)
From now on, x is 1 and y is 2. We can also write:
x, y = [1, 2]
Has the same effect. If we write: x, y = 1There is an error, except for the exact same error in one of your for loops.
x, y = 1
In the second f example the list [['one', 'two']]只有个元素,就是['one', 'two']。for循环要跑一次,这一次p, q就是['one', 'two'] is similar to the example above.
[['one', 'two']]
['one', 'two']
p, q
In the first example, a has two elements, namely 'one', 'two'. The assignment is uncertain on p and q. In the second example, a has an element ['one', 'two' '], the order is determined.
p, q = [x, y] //可行 p, q = x, y//不确定
In Python, a for loop runs through each element in a list (or generator). So the correct form of the first loop is:
In addition, in Python we can write:
From now on, x is 1 and y is 2. We can also write:
Has the same effect.
If we write:
x, y = 1
There is an error, except for the exact same error in one of your for loops.In the second f example the list
[['one', 'two']]
只有个元素,就是['one', 'two']
。for循环要跑一次,这一次p, q
就是['one', 'two']
is similar to the example above.In the first example, a has two elements, namely 'one', 'two'. The assignment is uncertain on p and q.
In the second example, a has an element ['one', 'two' '], the order is determined.