简体   繁体   中英

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)

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

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