Home > other >  Python error list indices must be integers or slices, not STR
Python error list indices must be integers or slices, not STR

Time:11-15

Aliens=[];/* define an empty column
For alien_number in range (0, 10) :/
New_alien={' color ':' green 'and' points' : 5, 'speed' : 'missile'}
Aliens. Append (new_alien);
Print (aliens);
For alien in aliens (3-0) :
# ~ print ('... ')
# ~ print (aliens)
If aliens [' color ']=='green' :/* list indices must be integers or slices, not STR error here, I don't know how, which tall person to see
Aliens [' color ']='red'
Aliens [' points']=10
Aliens [' speed ']='fast'
Print (aliens);

CodePudding user response:

If aliens [' color ']=='green' :/* list indices must be integers or slices, not STR error here, I don't know how, which tall person to see
Aliens [' color ']='red'
Aliens [' points']=10
Aliens [' speed ']='fast'
Print (aliens);
Here have the wrong number, should be alien
If alien [' color ']=='green' :
Alien [' color ']='red'
Alien [' points']=10
Alien [' speed ']='fast'
Print (alien);

CodePudding user response:

Aliens is a list, there are a lot of alien
Alien is a dictionary, the key includes color, points, speed

CodePudding user response:

I see again, thank you, really thank you
  • Related