[python] Pulnocni rozjimani :-)

Vladimir Macek macek na sandbox.cz
Pondělí Květen 11 23:11:34 CEST 2015


Inspirovan, jeste malicko rozvinu. :-)

    >>> a = 257
    >>> b = 257
    >>> a is b
    False
    >>> c = d = 257
    >>> c is d    # logicky True
    True
    >>> e, f = 257, 257     # tohle je vsak zajimave
    >>> e is f
    True
    >>> g = 'nazdar'
    >>> h = 'nazdar'
    >>> g is h
    True
    >>> i = 'nazdar'*1000
    >>> j = 'nazdar'*1000
    >>> i is j
    False
    >>> i == j
    True
    >>> k = intern(i)
    >>> l = intern(j)
    >>> k is l
    True



On 11.5.2015 12:46, Pavel Schön wrote:
> $ python
> Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32) 
> [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
>>>> a = 256
>>>> b = 256
>>>> a is b
> True
>>>> a = 257
>>>> b = 257
>>>> a is b
> False
>
>
> On Sunday, May 10, 2015 at 1:05:58 AM UTC+2, Vladimir Macek wrote:
>> Just having fun.
>>
>>     $ python
>>     >>> a = {}
>>     >>> b = {'a': a}
>>     >>> a['b'] = b
>>     >>> a
>>     {'b': {'a': {...}}}
>>     >>> b
>>     {'a': {'b': {...}}}
>>     >>> import cPickle
>>     >>> ap = cPickle.dumps(a)
>>     >>> del a, b
>>     >>> len(ap)
>>     26
>>     >>> a = cPickle.loads(ap)
>>     >>> a
>>     {'b': {'a': {...}}}
>>     >>> a['b']
>>     {'a': {'b': {...}}}
>>     >>> a['b']['a']
>>     {'b': {'a': {...}}}
>>     >>> a['b']['a']['b']
>>     {'a': {'b': {...}}}
>>     >>>
>>
>> Navaze nekdo? :-)
>>
>> V.
>>
>>
>> --- news://freenews.netfront.net/ - complaints: news na netfront.net ---
>


-- 
:  Vladimir Macek  :  http://macek.sandbox.cz  :  +420 608 978 164
:  UNIX && Dev || Training  :  Python, Django  :  PGP key 97330EBD
:  http://macek.sandbox.cz/skoleni/



Další informace o konferenci Python