Ask Your Question

Revision history [back]

You can prefix your string with the letter u to mark it as a unicode string, eg u'gömböc'.

EDITED. My original answer was missing the point. This is maybe more a related discussion than an answer.

You can prefix your a string with the letter u to mark it as a unicode string, eg u'gömböc'.

string. If you are inputting unicode characters, this will affect how the string is encoded.

Here is what I get in the Sage REPL.

sage: 'Erdős'
'Erd\xc5\x91s'
sage: u'Erdős'
u'Erd\u0151s'

This shows a difference in the escape codes used for accented characters.

Apparently @kcrisman's indication to use print is the key to properly displaying unicode strings.

sage: print 'Erdős'
Erdős
sage: print u'Erdős'
Erdős

The role of the u prefix is not so apparent here.

The u is useful if you are using unicode escape codes in the string.

sage: print 'Erd\u0151s'
Erd\u0151s
sage: print u'Erd\u0151s'
Erdős

The other version:

sage: print 'Erd\xc5\x91s'
Erdős

EDITED. My original answer answer

You can prefix a string with the letter u to mark it as a unicode string, eg u'gömböc'.

was missing the point. This is not so helpful. The notes below are maybe more a related discussion than an a proper answer.

You can prefix a string with the letter u to mark it as a unicode string. If you are inputting unicode characters, this will affect how the string is encoded.

Here is what I get in the Sage REPL.

sage: 'Erdős'
'Erd\xc5\x91s'
sage: u'Erdős'
u'Erd\u0151s'

This shows a difference in the escape codes used for accented characters.

Apparently @kcrisman's indication to use print is the key to properly displaying unicode strings.

sage: print 'Erdős'
Erdős
sage: print u'Erdős'
Erdős

The role of the u prefix is not so apparent here.

The u is useful if you are using unicode escape codes in the string.

sage: print 'Erd\u0151s'
Erd\u0151s
sage: print u'Erd\u0151s'
Erdős

The other version:

sage: print 'Erd\xc5\x91s'
Erdős