Ask coding questions

← Back to all posts
How do I read 1 value from a list
LukeShomper (49)

Can Pop(0) be used or something like Getting 1 value from a list
or should I use something like
Tea = ["Bob", "Ross", "Has", "Tea"]
And like print(FromTeaGet(0))
And then the console would say
And if I did print(FromTeaGet(1))
The console would say
I have googled it and am still confuused

Answered by mwilki7 (993) [earned 5 cycles]
View Answer
mwilki7 (993)

If you want to get a value from a list use brackets list[index]
Popping from a list means removing either from the front or back of the list (depending on how the list is coded)

        Mage[0] Mage[1] Mage[2] Mage[3]
            |       |       |       |
            |       |       |       |
            v       v       v       v
Mage = [    100,    100,    50,     50]

                Mage[0] Mage[1] Mage[2]                     new list of size 1
                    |       |       |                               |
                    |       |       |                               |
                    v       v       v                               v
Pop(): Mage = [    100,    100,    50]   Popped the end off! -->  [50]
LukeShomper (49)

@mwilki7 Kinda confused would It be
or is it mage[index]
bit confused
because I don't know the syntax trying to figure it out

LukeShomper (49)

Like, give me an example; Code so I can copy past and see how it works and like learn something new :D

mwilki7 (993)

Say you want to show everything inside the mage list (make sure the spelling/capitalization is correct):

for item in Mage:

Or using a for range loop

for i in range(0, len(Mage)):

Or maybe you just want to get something from a certain index:

myHP = Mage[0]