#-*-coding:utf-8 -*-
'''
Created on 2014年11月5日
@author: Zroad
'''
import sys
#将字符串转换为序列
strList = list("Hello,python!")
print strList
#遍历字符串中的任意一字符
for char in "Hello,python!":
#print char
#print char, #print不换行的处理
sys.stdout.write(char)
sys.stdout.flush()
print '\n'
#输出字符串不换行的第二种处理
sys.stdout.write("Hello,world!")
sys.stdout.flush()
#使用map函数遍历字符串中的每个字符
results = map(ord,"hello,python")
print results
#ASC||/Unicode单字符串与码值转换
print ord('a') #ASC||字符串 ‘a’对应的码值
print chr(97) #ASC||码97对应的字符
#str()与repr()的区别,str函数针对的是ASC||码
print ord(u'\u2020') #Unicode字符\u2020对应的码值
print repr(unichr(8224)) #将unicode码值转换为Unicode字符
#1、判断str/Unicode字符串对象
def isAString(anobj):
return isinstance(anobj,basestring)
print isAString('Hello,pyton')
print isAString(u'\8338')
print isAString(3990)
print isAString(chr(58))
#2、字符串左、中、右对齐
print "|",'hello,python'.rjust(20,'+') #width参数表示长度,包括对齐的字符串+间隔字符
print '|','hello,python'.ljust(20,'*')
print '|','hello,python1'.center(20,'-') #不加第二个参数默认添加空格
#3、去除字符串两端空格
x = " hello,python "
print x.lstrip()+'here'
print x.strip()
print x.rstrip()
y = "here, hello,python, here"
print y.strip('hre') #去除字符串y左右两边的'h'/'r'/'e'字符
#4、字符串合并
strs = ['hello',',','python']
print '/'.join(strs) #join函数接受字符串列表参数
#使用格式化字符串合并字符串是最优的选择
name = 'Zroad'
number = 100
print "Hello,%s;Go and %d" %(name,number)