Printing 2 parts of a list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Printing 2 parts of a list

If I have a list and want to print 2 parts, is there an easier way to print them than this? list = [1,2,3,4] print(list[1], list[2])

11th Dec 2016, 7:01 PM
Chance Moore
Chance Moore - avatar
3 Answers
0
hardly, actually. But be careful with your indexes, I just want to make sure you really want to print the second and third items in that list ?
11th Dec 2016, 10:35 PM
Amaras A
Amaras A - avatar
0
Yeah I know it would be the 2nd and 3rd items in the list. Thanks for the response, I'm kind of surprised there isn't a shortcut there.
11th Dec 2016, 10:50 PM
Chance Moore
Chance Moore - avatar
0
maybe using list[1:3] but you end up with a list, so it prints as a list... There is no shortcut that I know of, sadly...
11th Dec 2016, 10:59 PM
Amaras A
Amaras A - avatar