A
A
andrey_programm3r2020-06-06 00:44:56
Python
andrey_programm3r, 2020-06-06 00:44:56

How to display an item in a list?

Good afternoon everyone. Tell me, how can I enter a number and display exactly the number of elements that I entered from the list? For example:

a = ['раз', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь', 'восемь', 'девять', 'десять']
n = int(input('число, сколько слов нужно вывести'))


If I enter the number 3, then it should display the first three elements from the list, namely: one, two, three. How to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2020-06-06
@andrey_programm3r

>>> a = ['раз', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь', 'восемь', 'девять', 'десять']
>>> n = 1
>>> a[0:n]
['раз']
>>> n=3
>>> a[0:n]
['раз', 'два', 'три']
>>> n=5
>>> a[0:n]
['раз', 'два', 'три', 'четыре', 'пять']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question