Python Forum
How do you get Python to print just one value in a list? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How do you get Python to print just one value in a list? (/thread-39975.html)



How do you get Python to print just one value in a list? - 357mag - May-14-2023

If I just want Python to print the value in a certain index position in list how do I do it?

This is not giving me what I want:

numbers = [2, 4, 6, 8]
    
    print ([0])
    



RE: How do you get Python to print just one value in a list? - buran - May-14-2023

print(numbers[0])
If you don't mention the name, how it will know from which list (there may be plenty) :-)
Right now you just print list with one element


RE: How do you get Python to print just one value in a list? - 357mag - May-14-2023

I think I got it.

numbers[2]


RE: How do you get Python to print just one value in a list? - rob101 - May-17-2023

As a bit of an explainer on indexing:

 position:   |  0  |  1 |  2  |  3  |  4  |
 data:       |  a  |  b |  c  |  d  |  e  |
- position:  | -5  | -4 | -3  | -2  | -1  |
The above shows how any indexed object (of which a list object is one example) can be accessed.

For example:

list_data = ['a', 'b', 'c', 'd', 'e']

string = 'abcde'

... to name but two.