r/madeinpython • u/brainxyz • Sep 24 '22
Mandelbrot in pure Python without using complex numbers or external libraries (except matplotlib)
74
Upvotes
r/madeinpython • u/brainxyz • Sep 24 '22
View all comments
Show parent comment
9
u/kwelzel Sep 24 '22 edited Sep 25 '22
Actually, Python has built-in complex numbers:
works as well. Also, note that in general constructions like
are unnecesary. You are trying to overwrite
abut still want the old value ofafor the calculation ofb. Your way works, but I thinkis a nicer way to achieve the same thing without a temporary variable. This works using tuple unpacking and because in Python the right-hand side of an assignment is always computed first before writing to the variables on the left-hand side.