M
M
Maximka1232018-06-26 10:30:27
Python
Maximka123, 2018-06-26 10:30:27

How to display a list with numbering in Python 3.6.5?

Good day to all. I'm sorry for the stupid question, but could you help me make a list of five elements and then use the loop to display this list by numbering it. It should look like this:
1 pasta
2 cheese
3 milk
... etc.
I created a list. I take it out but I don’t understand how to number it! Can you help and most importantly explain this. Or give a link to a similar article. These cycles are very difficult for me.

ingridient = ['молоко', 'сыр', 'творог', 'кефир', 'яблоко']
for i in ingridient:
  print ("%s", %, i)

Gives an error message (((

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
planc, 2018-06-26
@Maximka123

items = ['молоко', 'сыр', 'творог', 'кефир', 'яблоко']
for i, item in enumerate(items):
    print(i + 1, item)

V
Vapekreng, 2018-07-17
@Vapekreng

items = ['milk', 'cheese', 'cottage cheese', 'kefir', 'apple']
length = len(items)
for i in range(length):
print(str(i + 1), item[i] )

Q
Qumm, 2021-03-05
@Qumm

items = ['milk', 'cheese', 'cottage cheese', 'kefir', 'apple']
length = len(items)
for i in range(length):
print(str(i + 1), item s[ i ])
forgot the 's' at the end of the variable name items

L
Latunio, 2022-01-05
@Latunio

a = ['one','two','three']
x = 0
b = x
for i in a:
b = b + 1
print('%s) %s' % (b, i))
Simple , for newbies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question