-2

I want to get an output like this

name1
name2
name3
name4

to n number of names with suffix as the range of x. How to use for loop to generate this kind of output?

Atom
  • 132
  • 3
  • 11

1 Answers1

1

For printing variables within strings, you can use f-strings since Python 3.6, as in the following example:

Code:

for i in range(1, 5):
    print(f"name{i}")

Output:

name1
name2
name3
name4
CDJB
  • 13,204
  • 5
  • 27
  • 47