- 1.1m
- 326
- 4.2k
- 3.5k
Can someone explain me why after the for loop the list res is = [‘m’]['m']?
string = ‘spam’'spam'
for x in string:
res =[]
res.extend(x)
print(res)
I expected the output to be res = [‘s’['s', ‘p’'p', ‘a’'a', ‘m’]'m']
Can someone explain me why after the for loop the list res is = [‘m’]?
string = ‘spam’
for x in string:
res =[]
res.extend(x)
print(res)
I expected the output to be res = [‘s’, ‘p’, ‘a’, ‘m’]
Can someone explain me why after the for loop the list res is ['m']?
string = 'spam'
for x in string:
res =[]
res.extend(x)
print(res)
I expected the output to be res = ['s', 'p', 'a', 'm']
Python: append/ extend method
Can someone explain me why after the for loop the list res is = [‘m’]= [‘m’]?
string = ‘spam’ for x in string: res =[] res.extend(x) print(res)
string = ‘spam’
for x in string:
res =[]
res.extend(x)
print(res)
I expected the output to be res = [‘s’, ‘p’, ‘a’, ‘m’]res = [‘s’, ‘p’, ‘a’, ‘m’]
Can someone explain me why after the for loop the list res is = [‘m’]?
string = ‘spam’ for x in string: res =[] res.extend(x) print(res)
I expected the output to be res = [‘s’, ‘p’, ‘a’, ‘m’]
Can someone explain me why after the for loop the list res is = [‘m’]?
string = ‘spam’
for x in string:
res =[]
res.extend(x)
print(res)
I expected the output to be res = [‘s’, ‘p’, ‘a’, ‘m’]