简体   繁体   中英

Why do I keep getting the same outputs?

I am creating a for loop and I keep getting the output twice:

    totalelements = len(uniquevalueslist)
    for id in [23, 45, 76]:
        if id not in uniquevaluelist:
            stmt = f"""INSERT INTO..."""
            for x in range(totalelements):
                stmt = stmt + f" SELECT...."
                if x < totalelements-1:
                    stmt = stmt + "UNION ALL " 
                else:
                    stmt += stmt   

my output is that I get the INSERT INTO Statement Twice

the if statement is inside the for loop. this means it will be evaluated each time you loop through the items.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM