Just a simple question:
str = ['blah','blah']
for word in str:
word = word * 2
print str
This just prints [‘blah’,’blah’]. Why (I know how to do this, just wondering why this isn’t allowed)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The issue is that you have created a new string, but not updated the reference in the str list. This means that
affects the variable word that has a new address, and this address (reference)
is not updated to the str list. to do that you need to:
or