Python Forum
How do you get Python to print just one value in a list?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you get Python to print just one value in a list?
#1
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])
    
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I think I got it.

numbers[2]
Reply
#4
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.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Print List to Terminal DaveG 2 1,428 Apr-02-2022, 11:25 AM
Last Post: perfringo
  Print max numbers in a list jimmoriarty 1 2,144 Sep-25-2020, 07:29 AM
Last Post: DPaul
  Print variable values from a list of variables xnightwingx 3 2,614 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  Print the number of items in a list on ubuntu terminal buttercup 2 1,930 Jul-24-2020, 01:46 PM
Last Post: ndc85430
  taking input doesnt print as list bntayfur 2 2,095 Jun-04-2020, 02:48 AM
Last Post: bntayfur
  Taking brackets out of list in print statement pythonprogrammer 3 2,376 Apr-13-2020, 12:25 PM
Last Post: perfringo
  Trying to print corresponding elements in two different list Darthmarvolo 5 2,576 Mar-03-2020, 04:29 AM
Last Post: perfringo
  printing a list contents without brackets in a print statement paracelx 1 2,107 Feb-15-2020, 02:15 AM
Last Post: Larz60+
  Trying to print an uneven list to a even table Mike2607 6 2,902 Nov-19-2019, 06:14 AM
Last Post: perfringo
  print all method and property of list object engmoh 4 2,830 Oct-26-2019, 05:33 PM
Last Post: engmoh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020