Python Increment Int variable in a String
Question: I can't seem to make a variable that prints out a line of text and next to it
a variable containing an integer that increments each time the for loop is
executed. This is my code:

    
    
    id = 1
    for x in range(0, 4):
     studentID = 'Bart: ' + `id`
     print(studentID)
     id += 1
    

The loop executes four times but it just prints out

    
    
    Bart: 1
    Bart: 1
    Bart: 1
    Bart: 1
    

for four times it doesn't increment the `id` integer


Answer: Try this:

    
    
    id = 1
    for x in range(1, 4):
        studentID = "Bart: {}".format(id)
        print(studentID)
        id += 1
    

But, why are you incrementing id inside a for loop? Why not just use the for
loop?

Edit: Also, you can use `print("Bart: ", id)`. And, if you want them all on
the same line as you show, you can use either of these:

    
    
     print("Bart: ", id, end="")
    

or

    
    
    sys.stdout.write("Bart: ") 
    sys.stdout.write(str(id))
    sys.stdout.write(" ")
    

You will need `import sys` at the top of your file.

These are Python 3+ solutions.

