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


Groups > comp.lang.python > #103848

Re: Explaining names vs variables in Python

From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Newsgroups comp.lang.python
Subject Re: Explaining names vs variables in Python
Date 2016-03-02 10:08 +0100
Message-ID <mailman.97.1456909764.20602.python-list@python.org> (permalink)
References <a894d5ed-d906-4ff7-a537-32bf0187e062@googlegroups.com>

Show all headers | View raw


On 02/03/2016 09:32, Salvatore DI DIO wrote:
> Hello,
>
> I know Python does not have variables, but names.
> Multiple names cant then be bound to the same objects.
>
> So this behavior 

Python has variables. They are just not the kind of variables
you find in C and variations but more like variables in lisp,
scheme and smalltalk.
 

>>>> b = 234
>>>> v = 234
>>>> b is v
> True
>
> according to the above that is ok

No that is just a coincidence. A consequent of the particular
implimentation, that has prepared a number of number objects
beforehand. There is no guarantee in the language that the
third statement above will produce True.

> But where is the consistency ? if I try :
>
>>>> v = 890
>>>> w = 890
>>>> v is w
> False
>
> It is a little difficult to explain this behavior to a newcommer in Python.

This behaviour is undefined in the language. So there is nothing to explain
except that it depends on implementation details. Any program that depends
on two variable being the same or not the after similar code is wrong.

-- 
Antoon Pardon

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


Thread

Explaining  names  vs variables  in Python Salvatore DI DIO <salvatore.didio@gmail.com> - 2016-03-02 00:32 -0800
  Re: Explaining names vs variables in Python Jesper K Brogaard <jesper@brogAAaard.eu> - 2016-03-02 10:03 +0100
    Re: Explaining names vs variables in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-02 21:32 +1100
      Re: Explaining names vs variables in Python Marko Rauhamaa <marko@pacujo.net> - 2016-03-02 14:34 +0200
        Re: Explaining names vs variables in Python Chris Angelico <rosuav@gmail.com> - 2016-03-02 23:50 +1100
          Re: Explaining names vs variables in Python Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-02 15:11 +0200
          Re: Explaining names vs variables in Python Marko Rauhamaa <marko@pacujo.net> - 2016-03-02 15:39 +0200
            Re: Explaining names vs variables in Python Chris Angelico <rosuav@gmail.com> - 2016-03-03 00:48 +1100
              Re: Explaining names vs variables in Python Marko Rauhamaa <marko@pacujo.net> - 2016-03-02 16:11 +0200
                Re: Explaining names vs variables in Python Rustom Mody <rustompmody@gmail.com> - 2016-03-02 07:08 -0800
                Re: Explaining names vs variables in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-03 04:23 +1100
                Re: Explaining names vs variables in Python Rustom Mody <rustompmody@gmail.com> - 2016-03-02 09:28 -0800
                Re: Explaining names vs variables in Python Marko Rauhamaa <marko@pacujo.net> - 2016-03-02 20:12 +0200
                Re: Explaining names vs variables in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-03 12:52 +1100
                Re: Explaining names vs variables in Python Rustom Mody <rustompmody@gmail.com> - 2016-03-03 09:03 -0800
                Re: Explaining names vs variables in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-03 12:53 -0700
                Re: Explaining names vs variables in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-02 21:49 +0000
                Re: Explaining names vs variables in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-03 13:05 +1100
                Re: Explaining names vs variables in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-03 16:09 +0000
                Re: Explaining names vs variables in Python Chris Angelico <rosuav@gmail.com> - 2016-03-03 08:52 +1100
                Re: Explaining names vs variables in Python Rustom Mody <rustompmody@gmail.com> - 2016-03-02 17:23 -0800
                Re: Explaining names vs variables in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-02 22:51 +0000
              Re: Explaining names vs variables in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-03 04:10 +1100
  Re: Explaining names vs variables in Python Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-02 10:08 +0100
  Effects of caching frequently used objects, was Re: Explaining  names  vs variables  in Python Peter Otten <__peter__@web.de> - 2016-03-02 10:12 +0100
  Re: Explaining  names  vs variables  in Python Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-02 11:35 +0200
    Re: Explaining names vs variables in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-02 08:13 -0700
      Re: Explaining names vs variables in Python Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-02 17:37 +0200
  Re: Explaining  names  vs variables  in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-02 21:16 +1100
  Re: Explaining  names  vs variables  in Python "ast" <nomail@invalid.com> - 2016-03-02 11:52 +0100
    Re: Explaining  names  vs variables  in Python Salvatore DI DIO <salvatore.didio@gmail.com> - 2016-03-02 02:58 -0800
  Re: Effects of caching frequently used objects, was Re: Explaining  names  vs variables  in Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-02 09:16 -0500
  Re: Explaining  names  vs variables  in Python Ben Finney <ben+python@benfinney.id.au> - 2016-03-03 04:53 +1100
  RE: Effects of caching frequently used objects, was Re: Explaining names  vs variables  in Python Albert-Jan Roskam <sjeik_appie@hotmail.com> - 2016-03-25 13:03 +0000
  Re: Effects of caching frequently used objects, was Re: Explaining names vs variables in Python Chris Angelico <rosuav@gmail.com> - 2016-03-26 00:22 +1100
  Re: Effects of caching frequently used objects, was Re: Explaining names  vs variables  in Python Ethan Furman <ethan@stoneleaf.us> - 2016-03-25 09:45 -0700

csiph-web