python trap

What will this code print?

for item in ('aaa'): print item


The result is:

a
a
a

I think you expected the following as the result:

aaa

I was near reporting a bug, but, fortunately, realized, that "('aaa')" is actually not a list, but a string in parenthesis. The correct way to get the desired result is:

for item in ('aaa',): print item

Vibe code with your voice

Stop fighting speech recognition.
Just talk → fix mistakes later

"... _brings_ hello world"   ❌
          ↓
"... _prints_ hello world"   ✅

Get handsfree.vc on Google Play

Categories: python

Updated: