name1 = u'xiaochao,"你好",\'你在成都好吗?\''
print name1
def add():
'''
None
:return:
'''
name = u'小超'
age = 24
address = u'成都'
print u'我在%s,今年我%s岁,我的名字是%s'%(address,age,name)
print u'我今年{1}岁了,我叫{0},在四川{2}'.format(name,age,address)
print u'我叫{name},我今年{age}岁了,我在{address}'.format(name=name,age=age,address=address)
'''字符串和unicode类型互转'''
str1 = 'hello'
print u'现在的类型是:',type(str1)
#字符串转为unicode用decode()
str2 = str1.decode('gbk')
print u'str2的类型是:',type(str2)
#unicode类型转为str
str3 = str2.encode('utf-8')
print u'str3的类型是:',type(str3)
''#将字符串转成int类src = '45'
src1 = int(src)#浮点类型float(src)
print u'将字符串强转为int类型:',type(src1)
name = 'my\tname is {name} and i am {age} old'
#首字母大写
print(name.capitalize())
#统计字符串中出现的数量
print(name.count('m'))
#打印10个-,并且将内容居中
print(name.center(10,'-'))
#将二进制转成字符串
print(name.encode())
#判断一个字符串以什么结尾
print(name.endswith('o'))
name1 = 'my \tname is xiaochao'
#输入\t(tab键)将tab键输入多少个间隔
print(name1.expandtabs(tabsize=10))
#查找字符串中的字符索引
print(name.find('y'))
#字符串切片
print(name[name.find('name'):])
#字符串格式化输出
print(name.format(name = 'xiaochao',age = 24))
#阿拉伯数字+字母
print(name.isalnum())
#判断是否为纯英文字符
print('sas1'.isalpha())
#是否是整数
print('22'.isdigit())
#判断是不是一个合法的标识符
print('A艾大df1'.isidentifier())
#判断是不是小写
print('set'.lslower())
#判断是不是一个纯数字
print('res1'.isnumeric())
#判断是不是空格
print('sd2'.isspace())
#判断每个首字母是否大写
print('my Name is'.istitle())
#大小写转换
print('das'.swapcase())
#判断是不是大写
print('das'.isupper())
#将列表以,拼接
print(','.join(['1','2','3']))
#字符串长度不够10就用*号向后补齐
print(name.ljust(10,'*'))
#字符串长度不够10就用-号向前补齐
print(name.rjust(10,'-'))
#首字母小写
print('Sr'.lower())
#左边有空格或者回车去掉输出
print('\nAstr'.lstrip())
#右边有空格或者回车会去掉输出
print('Astn\n'.rstrip())
#去掉空格或回车
print(' dasnt\n'.strip())
#小写转为大写
print('dfa'.upper())
#根据后面的字母找到对应的数字
p = name.maketrans('abcderf1','12345566')
print('xiaochao'.translate(p))
#替换
print(’sdw'.replace('s','A'))
#找到最右边一个值得下标
print('xiaochao'.rfind('a'))
#将字符串以空格拆分成列表
print('xiao chao'.split(' '))
#以换行拆分
print('xiao\nchao'.splitlines())
'''字符串的操作'''
cont = 'hell word'
print u'获取w在字符串中是第几位:',cont.index('w')#索引均是从0开始
print cont.index('l')
print u'取消字符串中的空格:',cont.strip()
cont.strip()
print u'判断字符串是否是数字:',cont.isdigit()
cont.isdigit()
print u'寻找字符串中的元素:',cont.find('o')
cont.find('s')
print u'替换字符串中的元素:',cont.replace('word','China')
cont.replace('word','name')
print u'字符串的拆分:',cont.split(' ')#字符串拆分处理以后就是列表
cont.split(' ')
print u'首字母变大写:',cont.capitalize()
cont.capitalize()
print u'内容居中:',cont.center(30,'=')
#cont.center(30,'==')
cont1 = 'Hello\t999'
print u'处理table键:',cont1.expandtabs()
print u'是否是字母和数字:',cont.isalnum()
print u'是否是字母:',cont.isalpha()
print u'判断是否是数字:',cont.isdigit()
print u'是否小写:',cont.islower()
print u'是否有空格:',cont.isspace()
print u'是否是大写:',cont.isupper()
#判断标题-->首字母大写,可以理解为大写
print u'首字母是否大写:',cont.istitle()
#join连接字符串
s1 = ['appium','selenium','android','ios']
print '连接字符串:', '***'.join(s1)
#使用.join()把列表转为字符串
print '把列表转成字符串:',','.join(s1)
#字符串转为列表
a = 'a b c'
print a.split(" ")
#移除空白
a1 = ' abc'
print '移除空白:',a1.lstrip()
#移除左侧空白
print '移除左侧空白:',a1.lstrip()
#移除右侧空白
st = 'hell '
print '移除右侧空白:',st.rstrip()
#字符串转小写
print cont.lower()
#分割字符串,分割之后就是元组
ss1 = 'xiaochao is python'
print u'分割字符串,分割之后就是元组:',ss1.partition('is')
#替换字符串
print u'替换字符串:',ss1.replace("xiaochao",'admin')
#rfind()从右向左找
print ss1.find('xiaochao')
#bytes可以将字符串转换成字节
# strs1 = u'小超'
# print u'字符串转成字节:',strs1.bytes(strs1)
![]()