-1

How can I increment these list string elements in a for loop?

mylist = ['and1', 'hello', 'world']

#some for loop
for i in np.linspace(start,stop,num_samples)
   print('This is %s' % mylist[0])

This gives output:

This is and1
This is and1
This is and1

My desired output is:

This is and1
This is hello
This is world

Is there an easy way to do this in python?

1 Answers1

2

mylist[0] always refers to the initial index in the list, while you probably meant mylist[i]

However, you can directly iterate over lists

for value in mylist:
    print(f"This is {value}")
ti7
  • 16,375
  • 6
  • 40
  • 68