Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103000
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | srinivas devaki <mr.eightnoteight@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Multiple Assignment a = b = c |
| Date | Tue, 16 Feb 2016 18:16:45 +0530 |
| Lines | 59 |
| Message-ID | <mailman.161.1455626848.22075.python-list@python.org> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de qec03PjlF5pSwh49NsyABQougm9CmPYUpNAVs/bJN4ow== |
| Return-Path | <mr.eightnoteight@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.031 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'assignment': 0.07; 'performs': 0.07; 'python': 0.10; 'output': 0.13; 'def': 0.13; '+91': 0.15; 'at-least': 0.16; 'chained': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'resolved': 0.18; 'student': 0.20; 'junior': 0.22; 'variables.': 0.22; 'references': 0.23; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'idea': 0.28; 'this.': 0.28; 'received:209.85.213.174': 0.29; 'fixed': 0.31; 'skip:_ 10': 0.32; 'class': 0.33; 'operations.': 0.33; 'received:google.com': 0.35; 'done': 0.35; 'expected': 0.35; "isn't": 0.35; 'but': 0.36; 'received:209.85': 0.36; 'indian': 0.36; 'to:addr:python-list': 0.36; 'received:209.85.213': 0.37; 'received:209': 0.38; 'skip:p 20': 0.38; 'hi,': 0.38; 'to:addr:python.org': 0.40; 'school': 0.62; 'great': 0.63; 'hours': 0.65; 'today': 0.65; 'teach': 0.70; '(3rd': 0.84; 'ph:': 0.84; 'ruled': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=2GXQZRusRWM7CyaRCZ8eyAwtO4ct4Hk8n5+eES6SOKY=; b=P6j3eZ6HI0H0jnplse6OzWtyNU6NTj6vPwGsFf/9nGQ1cKIIxhunIHfR4luBfC8hmN FkNsYWmmD+BnKTQVQYLys4rIHfPHTvDablwag1TzxnI0Db4YLMGarGW78/th5YXkvzZ2 pf0N/9LMtXVMJDR9WNa/F6fD/1qJ0yrVdic8SOvZWmceW8+6z6oaX9sprOQw8K9fHCpP kxDUuX7klau5gF99lQNS96xSadESw4Wadj5EvAOAHE5We83zAKr051wblwML/naJw6nY GPJWtoUlYnJVTWYI6nZ70sTnIJExAaJpexUXeM8DkZ7anL9UKpaqWlwF8UHTuuwZRQ+a MGcw== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=2GXQZRusRWM7CyaRCZ8eyAwtO4ct4Hk8n5+eES6SOKY=; b=mAqFcIvb670QcEouU68PMT0GMF2HHFVJcFcO8Tt3GX05vJhimQ7Hn/aWUhdX5KvSVh VXkZ0R8AHBsO1EoDeo/SYjwHkhafAQrsPwiD4Db1wibHi9Xe6W9FBNm+mTPmcLNjxBv4 5d5y2UO8WQeaXkm+02J/vQk0I7cFcNzvN0IC53BBPQtzlQtL1XxOrTgoHSKxjgj+TJaU +pakSfS+HlGFAUjaa3WtaF8qsqp5YjisxzSedAAFzTepTI26x6NOM8KR/LZEEYsdgLvR SkX/9uWuhehSd56DjgepkK0hexYeynkHOfyLbh02krwOHYyD+ZFF7GOHOREiqNPyaNaD c8Tg== |
| X-Gm-Message-State | AG10YORfPGDOTU8d5WQrZqtSSuysoUjWzhFyu0PGZq/SOlPBM1ShwpMctyh7hahBeP5aYk0Ikl9BZ3BnQasshA== |
| X-Received | by 10.50.150.106 with SMTP id uh10mr16421169igb.41.1455626844595; Tue, 16 Feb 2016 04:47:24 -0800 (PST) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21rc2 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:103000 |
Show key headers only | View raw
Hi,
a = b = c
as an assignment doesn't return anything, i ruled out a = b = c as
chained assignment, like a = (b = c)
SO i thought, a = b = c is resolved as
a, b = [c, c]
at-least i fixed in my mind that every assignment like operation in
python is done with references and then the references are binded to
the named variables.
like globals()['a'] = result()
but today i learned that this is not the case with great pain(7 hours
of debugging.)
class Mytest(object):
def __init__(self, a):
self.a = a
def __getitem__(self, k):
print('__getitem__', k)
return self.a[k]
def __setitem__(self, k, v):
print('__setitem__', k, v)
self.a[k] = v
roots = Mytest([0, 1, 2, 3, 4, 5, 6, 7, 8])
a = 4
roots[4] = 6
a = roots[a] = roots[roots[a]]
the above program's output is
__setitem__ 4 6
__getitem__ 4
__getitem__ 6
__setitem__ 6 6
But the output that i expected is
__setitem__ 4 6
__getitem__ 4
__getitem__ 6
__setitem__ 4 6
SO isn't it counter intuitive from all other python operations.
like how we teach on how python performs a swap operation???
I just want to get a better idea around this.
--
Regards
Srinivas Devaki
Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad)
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Multiple Assignment a = b = c srinivas devaki <mr.eightnoteight@gmail.com> - 2016-02-16 18:16 +0530
Re: Multiple Assignment a = b = c Steven D'Aprano <steve@pearwood.info> - 2016-02-17 02:16 +1100
Re: Multiple Assignment a = b = c srinivas devaki <mr.eightnoteight@gmail.com> - 2016-02-16 21:30 +0530
csiph-web