- import string
- print dir(str)
- print dir(string)
- print help(str.join)
-
- #from unicode to ascii : str()
- #from ascii to unicode : unicode()
- #str.encode()
- #str.decode()
- str_a = 'hello world'
- str_u = u'hello world'
- print str_u, unicode(str_a)
- print str_a, str(str_u)
- print str_a.decode()
- print str_u.encode()
-
- #str.join
- #str.split
- str_ip = '127.0.0.1'
- print str_ip.split('.')
- print 'www.python.org'.rsplit('.', 1)
- print '.'.join(str_ip.split('.'))
- print '.'.join(item for item in str_ip.split('.'))
- print '.'.join('1001')
-
- #str.find
- #str.rfind
- #str.index
- #str.count
- python_web = 'www.python.org'
- if python_web.find('python') == -1:
- print 'find it'
-
- print python_web.count('python')
-
- #str.startswith
- #str.endswith
- print python_web.startswith('www')
- print python_web.endswith('org')
-
- #str.title
- #string.capwords(s)
- #str.ljust
- #str.rjust
- #str.expandtabs
- str_h = 'hello world'
- print str_h.title()
- print string.capwords(str_h)
- print str_h.ljust(20)
- print str_h.rjust(20)