string literal vs string variable

Jan Kaliszewski zuo at chopin.edu.pl
Sat Aug 22 23:06:57 CEST 2009


22-08-2009 o 19:46:51 Kee Nethery <kee at kagi.com> wrote:

> I'm not sure I know the difference between a string variable and a  
> literal string. Is the difference as simple as:
>
> somestring = u'<stuff>hello world</stuff>'
> fromstring(somestring)  <-- string variable
> vs
> XML(u'<stuff>hello world</stuff>')  <-- literal string

Yes, simply:

     s = 'hello world'
     #    ^
     #    it is a *string literal*

     s  # <- it is a *string object*
        #    (or rather a name referring to it :-))

(In Python we have rather 'names' than 'variables', though -- as
a mental leap -- they are commonly referred to as 'variables',
regarding other languages' terminology).

Cheers,
*j

-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-list mailing list