May 18, 2013

Python Strings - III

1)
Pythonic way to copy a string/list
s[:]

IDLE 2.6.6    
>>> s = 'my new string'
>>> s
'my new string'
>>> s1 = s[:]
>>> s1


2)
Python % and Strings

python comes up with printf like % things.

IDLE 2.6.6    
>>> str = " I am learning %s since %d days " % ('python',5 )
>>> str
' I am learning python since 5 days '
>>>


After %, we need to provide tupple.


3).

Python Unicode Strings:

  
IDLE 2.6.6    

>>> str = u' Python Unicode \u018e '
>>> str
u' Python Unicode \u018e '
>>> s = str.encode('utf-8')
>>>
>>> s
' Python Unicode \xc6\x8e '
>>>