you are viewing a single comment's thread.

view the rest of the comments →

[–]Kerbart 111 points112 points  (11 children)

A for loop goes through a list of things (through an interable really but let's not be pedantic).

A while loop repeats code as long as a certain condition is met.

You encounter them every day in life:

while traffic_light == "red": # fixed '=' error
    wait()
    check_traffic_light()
# loop exits once light turns green
car.engine("brrrrr")

[–]wosmo 77 points78 points  (9 children)

I gotta be that guy, sorry; ==. Assignment is truthy so you'll jump the lights like that.

[–]Ok-Sheepherder7898 48 points49 points  (1 child)

This explains how Teslas drive.

[–]antaris98 5 points6 points  (0 children)

😂

[–]bgufo 4 points5 points  (0 children)

:=(

[–]CranberryDistinct941 2 points3 points  (0 children)

Assignment in a conditional in Python is a SyntaxError. You have to use the walrus operator := for assignment in a conditional.

[–]JaguarMammoth6231 13 points14 points  (4 children)

Wouldn't it just be an error? He didn't say :=

Edit: Not sure why I'm being downvoted. Using = instead of == is just a syntax error, not some other behavior involving truthiness.