[Tutor] Question
Joel Goldstick
joel.goldstick at gmail.com
Tue Jul 23 20:28:07 CEST 2013
On Tue, Jul 23, 2013 at 1:45 PM, Don Jennings <dfjennings at gmail.com> wrote:
>
> On Jul 21, 2013, at 10:26 PM, Amandeep Behl wrote:
>
>>
>>
>> def Move(label):
>> label = "Anything"
>>
>> a_list = [1,2,3]
>> Move(a_list)
>>
>> I don't see any error when executing above but when i manually assign [1,2,3] = "Anything" i get error
>> Why?
Don's answer is great. The meaning of 'Name' seems to be the most
common confusion to people learning to code python when having first
learned other languages. To your question above: what do you expect
to happen when you code this: [1,2,3] = "Anything"
>
> Repeat after me: label is a name, label is a name, label is a name ;>)
>
> So, you misunderstand what is happening in your code. Your function accepts the argument named "label", but you do nothing with the object (a list of numbers in this case). Instead, you use the same name and assign it to the string object "Anything".
>
> Assignment works by assigning a name (on the left side of the operator), to an object on the right side.
>
> Take care,
> Don
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
--
Joel Goldstick
http://joelgoldstick.com
More information about the Tutor
mailing list