2012年4月26日 星期四

Python 筆記- replace

'''
Created on 2012-5-1

@author: Maca
'''


str1 = "<<>>&&"
print str1.replace("<",">")


str2 = "abc"

for (a,b) in (("a","d"),("b","e"),("c","f")):
    str2 = str2.replace(a,b)
   
print str2

import cgi

str3 = ' <   >   &   " '

str3 = cgi.escape(str3,quote = True)

print str3

str3 = ' <   >   &   " '

str3 = cgi.escape(str3,quote = False)

print str3


>>>>&&
def
 &lt;   &gt;   &amp;   &quot; 
 &lt;   &gt;   &amp;   " 

沒有留言:

張貼留言