Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98849

Re: What function is 'u0, j = random(), 0'?

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Zachary Ware <zachary.ware+pylist@gmail.com>
Newsgroups comp.lang.python
Subject Re: What function is 'u0, j = random(), 0'?
Date Sat, 14 Nov 2015 20:47:15 -0600
Lines 53
Sender zachary.ware@gmail.com
Message-ID <mailman.346.1447556068.16136.python-list@python.org> (permalink)
References <f2965552-575a-44fc-9c34-dbc4792d4208@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de 4E2y7k0+vpIEuZyhkCho2w5k0n1XQIE31PBQBqXqrMIA==
Return-Path <zachary.ware@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'float': 0.05; 'indices': 0.07; 'lines:': 0.09; 'throw': 0.09; 'tuple': 0.09; 'unpacking': 0.09; 'received:209.85.218': 0.10; 'def': 0.13; '(everything': 0.16; '0")': 0.16; 'assignment.': 0.16; 'nameerror': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:random': 0.16; 'tuple,': 0.16; 'two,': 0.16; 'wrote:': 0.16; 'sender:addr:gmail.com': 0.18; 'creates': 0.18; '2015': 0.20; 'to:name:python-list@python.org': 0.20; 'fairly': 0.22; 'assuming': 0.22; 'code,': 0.23; 'sat,': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'example': 0.26; 'error': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; '14,': 0.27; 'values': 0.28; 'away.': 0.29; 'tutorial': 0.29; 'there.': 0.30; "i'm": 0.30; 'code': 0.30; 'skip:[ 10': 0.31; 'error.': 0.31; 'noticed': 0.32; 'run': 0.33; 'url:python': 0.33; 'int': 0.33; 'covered': 0.34; 'equal': 0.34; 'list': 0.34; 'gives': 0.35; 'received:google.com': 0.35; 'could': 0.35; 'nov': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'basic': 0.36; 'assigned': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'say': 0.37; '(with': 0.38; 'difference': 0.38; 'received:209': 0.38; 'names': 0.38; 'hi,': 0.38; 'to:addr:python.org': 0.40; 'questions': 0.40; 'future': 0.60; 'url:3': 0.60; 'hope': 0.61; 'side': 0.62; 'more': 0.63; 'information': 0.63; 'between': 0.65; 'believe': 0.66; 'day': 0.67; 'console,': 0.84; 'different.': 0.91; 'url:tutorial': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=DNWbotQVNqk4khkdQ0w9F6YGO6bTnzHSNbCEcy47yfE=; b=UzNAT/Jf78Bah0iyhQ/oc4CK2xYAZFWQsB1fZMZlAsa3RU+D7N4Z1T35l7JSCR7SLZ cR348qrVvN3OK1hMB6meSu4lLaGu61Cwfve+DqP3uICWiJaCCtLVaB3Hpuu65k7snlr6 raYSPggM+EtTXJv5auu1ZC9x39QooBCT6BNhmeLEg1m5I9qyEl48A42/r+xrlxL0zEuP bE6MchoTqj0kxYplGjF3DJNEMkt2y91RHFMzm6ZpV4BweJJtH+frqvVpUv8ZSmHBj/Fr 5EDlvesPKRO2Utd3SPDeW+B8+8h0Caq/odsBIhJz/ufHU81ceKRIAds8zoWm/N3iUgiE ktww==
X-Received by 10.202.192.67 with SMTP id q64mr16369800oif.60.1447555654308; Sat, 14 Nov 2015 18:47:34 -0800 (PST)
In-Reply-To <f2965552-575a-44fc-9c34-dbc4792d4208@googlegroups.com>
X-Google-Sender-Auth 5VKMSUWu2a_YIh5kntxmhVTlxfg
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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:98849

Show key headers only | View raw


Hi,

On Sat, Nov 14, 2015 at 8:23 PM, fl <rxjwg98@gmail.com> wrote:
> Hi,
>
> When I read the below code, I cannot make the last line (with ######) out.
>
>
>
> def res(weights):
>   n = len(weights)
>   indices = []
>   C = [0.] + [sum(weights[:i+1]) for i in range(n)]
>   u0, j = random(), 0  ######
>
>
> If I run below code on console, it will say an error.
>
> uu, 0.1, 0
>
>
> What difference is between these two example lines?

I've noticed you sending a lot of questions in the past day or two,
many at a fairly basic level.  I think you would be well-served to
read through the tutorial at https://docs.python.org/3/tutorial.  It's
been a while since I last read it, but I believe this question is
covered there.

To give to an answer anyway, the two lines ("u0, j = random(), 0" and
"uu, 0.1, 0") are very different.

The first is a tuple unpacking assignment.  The right side (everything
right of the equal sign) creates a tuple (comma creates a tuple, not
parentheses) of the result of calling the 'random', and 0. The left
side the equal sign is a list of names to which the right side values
are assigned; the result of random() is assigned to the name 'u0', and
0 is assigned to 'j'.  The same result could be achieved by the
following two lines:

   u0 = random()
   j = 0

The second line attempts to make a tuple out of the value assigned to
the name 'uu', the float 0.1, and the int 0, and throw it away.  I'm
assuming the error you got was a NameError because nothing was
assigned to 'uu', but I could be wrong.  For future questions, you
should copy and paste the full traceback, which gives *a lot* more
information than "there was an error".

Hope this helps,
-- 
Zach

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What function is 'u0, j = random(), 0'? fl <rxjwg98@gmail.com> - 2015-11-14 18:23 -0800
  Re: What function is 'u0, j = random(), 0'? Zachary Ware <zachary.ware+pylist@gmail.com> - 2015-11-14 20:47 -0600
  Learning Python from the tutorial (was: What function is 'u0, j = random(), 0'?) Ben Finney <ben+python@benfinney.id.au> - 2015-11-15 14:03 +1100

csiph-web