I've got a python printing question

suppose I have a list code
a=[ 1 , 2 , 3, 4 ,5 ,6]
now I have to print 1,2,3,4,5,6 on a separate line individually which can be done by this simple code
print(*a, sep=“\n”)
but how can I print it this way
1 this is 1
2 this is two
3 this is 3
4 this is four
do I need to use a for loop? if so how can someone explain I’m pretty weak on the for loop concept :smiling_face_with_tear:
edit, after \n I can write this as 1 but it’ll continue with 1 and won’t change on the time of 2,3, or 4 so how do I do it?

Hey! If you define a list in the line
list = [1,2,3,4,5]
you can loop the list by doing the following code:

for x in list:
print(x) #x in this case is one of the integers defined in the list

Hope this helps!

1 Like

ah no, u didn’t get the question I’m asking lol sorry,
I can write the separate line without using loops that are not my query I’m asking to know how i put separate titles for the separate numbers
like 1 will say this is 1, 2 will say this is two (two in words to make the difference ik its possible but dk how lol)

That is the right idea but wrong syntax, you need to indent the second line.

a = [(1, "1"), (2, "two"), (3, "3") etc.]
for num, name in a:
   print(f"{num} this is {name}")

nice I knew bout this
for numbers in a:
print (numbers, “this is number”, numbers)
but didn’t knew we can put tuples inside list noice thnx

1 Like

In python, you can put anything inside a list as it is not typed.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.