-3

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?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Atom
  • 320
  • 1
  • 6
  • 14

1 Answers1

0

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
  • 14,043
  • 5
  • 29
  • 55