string literal vs string variable

Jan Kaliszewski zuo at
Sat Aug 22 23:06:57 CEST 2009

22-08-2009 o 19:46:51 Kee Nethery <kee at> 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).


Jan Kaliszewski (zuo) <zuo at>

More information about the Python-list mailing list