Why is Your Python Programming Printing Duplicate Lines?

Problem scenario
You have a Python program with print statements. When you run the program, you get twice as many print statements as you expect. What could be wrong?

Possible Solution #1
Do not name the program re.py or string.py. When you name the program re.py and have an import re statement, Python may print every line it is supposed to print twice. When you name the program string.py and have an import string statement, Python may print every line it is supposed to print twice.

Possible Solution #2
Verify the logic in your program. Some for loops can execute more times than you realize.

Leave a comment

Your email address will not be published. Required fields are marked *