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


Groups > comp.lang.python > #19604

Re: add two strings

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: add two strings
Date 2012-01-30 10:08 -0500
References <CA+YdQ_6cp=9dQ65P3TTNTJLG54stCiX9x1RNSV=4akVQQKUTFw@mail.gmail.com> <4F2699CA.8070305@davea.name>
Newsgroups comp.lang.python
Message-ID <mailman.5216.1327936130.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, 30 Jan 2012 08:23:22 -0500, Dave Angel <d@davea.name> wrote:

>On 01/30/2012 08:02 AM, contro opinion wrote:
>>>>> s1='\x45'
>>>>> s2='\xe4'
>>>>> s1+s2
>> 'E\xe4'
>>>>> print  s1+s2
>> E
>>
>> why  s1+s2  not  =  '\x45\xe4'??
>>
>It is.  "E" is  "\x45".  That's plain ASCII and documented everywhere.

	The second factor is that "print" produces a "user-world" rendition,
whereas the interpreter without using print is producing a
representation suitable as a string literal within Python source code.

(Hmmm, PythonWin displayed inverse video hex value, which didn't
cut&paste to Agent well)

>>> s1 = "\x45"
>>> s2 = "\xe4"
>>> cat = s1 + s2
>>> print "string: %s\tliteral: %r" % (cat, cat)
string: E?iteral: 'E\xe4'
>>>

(and using Windows command line to invoke an interactive session
resulted in showing a cap-Sigma -- which also did not cut&paste well)

C:\Users\Wulfraed>python
ActivePython 2.7.1.4 (ActiveState Software Inc.) based on
Python 2.7.1 (r271:86832, Feb  7 2011, 11:30:38) [MSC v.1500 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> s1 = "\x45"
>>> s2 = "\xe4"
>>> cat = s1 + s2
>>> print "string: %s\tliteral: %r" % (cat, cat)
string: ES      literal: 'E\xe4'
>>>
 
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Thread

Re: add two strings Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-01-30 10:08 -0500

csiph-web