BorangeOrange1337
BorangeOrange1337

Reputation: 303

Why Does This Simple Python Script Break The Interpreter?

I was messing around earlier this afternoon and came to find that this simple script breaks the interpreter when I go to run it. Perhaps a silly question, but could someone be as kind as to explain why this is? It seems like a pretty simple execution... I assume it has something to do with the circular reference this is taking place?

artists = ['Picasso']

for artist in artists:
  artists.append(str(artist) + 'is the best.')
print(artists)

Upvotes: 0

Views: 59

Answers (1)

Holden
Holden

Reputation: 642

It's a never-ending loop because you are constantly staying one step ahead of the for loop because every loop you add one to the list

Upvotes: 6

Related Questions