Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.038 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'string.': 0.04; '===': 0.09; 'python': 0.11; 'subject:python': 0.14; '"new': 0.16; 'objects?': 0.16; 'subject:class': 0.16; 'subject:object': 0.16; 'subject:type': 0.16; 'wrote:': 0.16; 'string': 0.17; '(not': 0.20; 'bit': 0.23; '2015': 0.23; 'seems': 0.24; 'header:In-Reply- To:1': 0.24; 'message-id:@mail.gmail.com': 0.28; 'skip:( 20': 0.28; 'accomplished': 0.29; 'equivalent.': 0.29; 'implicitly': 0.29; 'objects': 0.29; "can't": 0.32; 'class': 0.33; 'third': 0.33; 'steven': 0.33; 'add': 0.34; 'received:google.com': 0.34; 'to:addr:python-list': 0.35; 'done': 0.35; 'false': 0.35; 'but': 0.36; 'subject:: ': 0.37; "skip:' 20": 0.37; 'tue,': 0.38; 'pm,': 0.39; 'method': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'here.': 0.61; 'detail.': 0.66; 'believe': 0.67; 'accessed.': 0.84; 'batchelder': 0.84; 'to:name:python': 0.84; 'utc-4,': 0.84; 'many,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=gwKTVwrX84GdfMWB9UHvGIww8eONOliYPxLKG4xZMz4=; b=YD0kX/5NtT2NqlNV6AsL2sFMU2zcnDknwlatW/om7mE+dyouSPP/54ptWkRXukRMOE wZvPkAVoLEhWm9JbqAGX5e/3wJihj0LBc1PkMoiEZliP3cePFyFjUlifYnd6FrokDDUl kmoN7XWk7xR3i6vPbww7zGWXh+V7Sbe2NJsDzKuL22vBDx5ulwUbhEDoFuQF9/wXzptO 5qgcUuvuFL8E0vQ8EaYSpjLJVMwApE2DjynsgGA6F9zeLIrArWdxcSIYncAw68wy5nOI 7Hbu5/8K8uEoIKduZa1E44gklsb/DNc8I6eTz4PHlvjCFy7cZ4jCkn/6LVu6OTTZBHRk 4vGQ== X-Received: by 10.107.6.136 with SMTP id f8mr34435964ioi.61.1433273817426; Tue, 02 Jun 2015 12:36:57 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <4d0ad8f5-d29f-442e-9374-5cda12153f88@googlegroups.com> References: <14976c1b-a620-426f-b529-41a3c04e9c1a@googlegroups.com> <48fc36e9-fa67-45d5-9864-0921b7e819ce@googlegroups.com> <556d931a$0$12991$c3e8da3$5496439d@news.astraweb.com> <556de143$0$13009$c3e8da3$5496439d@news.astraweb.com> <%9mbx.608935$JH2.445461@fx11.am4> <4d0ad8f5-d29f-442e-9374-5cda12153f88@googlegroups.com> From: Ian Kelly Date: Tue, 2 Jun 2015 13:36:16 -0600 Subject: Re: Everything is an object in python - object class and type class To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433273826 news.xs4all.nl 2868 [2001:888:2000:d::a6]:57029 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91886 On Tue, Jun 2, 2015 at 12:10 PM, Ned Batchelder wrote: > On Tuesday, June 2, 2015 at 1:59:37 PM UTC-4, BartC wrote: >> Javascript primitives include Number and String. >> >> What does Python allow to be done with its Number (int, etc) and String >> types that can't be done with their Javascript counterparts, that makes >> /them/ objects? > > They have methods (not many, but a few): > >>>> i, f = 1000001, 2.5 >>>> i.bit_length() > 20 >>>> i.to_bytes(6, "big") > b'\x00\x00\x00\x0fBA' >>>> f.as_integer_ratio() > (5, 2) >>>> f.hex() > '0x1.4000000000000p+1' To add a wrinkle to this discussion, Javascript numbers also have methods: js> (24).toExponential(3) "2.400e+1" I believe this is accomplished by implicitly boxing the number in the Number class when a method or property is accessed. This can be seen with: js> (24).toSource() "(new Number(24))" Note that "24" and "new Number(24)" are not equivalent. js> 24 === 24 true js> 24 === new Number(24) false js> typeof(24) "number" js> typeof(new Number(24)) "object" But this is a bit of an implementation detail. So what distinguishes Javascript primitives from objects? Steven listed "identity" as a third property of objects upthread; that seems applicable here.