#-*- coding:utf-8 -*-
#Author:gxli
#字符串的操作
name=' zhangsan,lisi,wangwu '
#分割操作
name=name.split(',')
print(name)#[' zhangsan', 'lisi', 'wangwu ']
#列表转字符串拼接
name='|'.join(name)
print(name)# zhangsan|lisi|wangwu #去除开头结尾制定字符
name2=' lgx '
name2=name2.strip()#name2=name2.strip(' ')
print(len(name2))#3
#特殊显示
print(name2.center(40,'-'))#------------------lgx-------------------
#查找字符并显示字符的下标
print(name2.find('g'))#1
#判断是否包含空格
print(' ' in name2)#False
#首字母大写
print(name2.capitalize())#Lgx #格式化显示
msg="hello, {name} it's been along {age}"
msg2=msg.format(name='lll',age=22)
print(msg2)
#isdigit()判断是否为数字
age=input('your age:')
if age.isdigit():
age=int(age)
else:
print('invalid data type') #判断是否包含违法字符
name3='ale3sdf'
print(name3.isalnum())
#判断是否已dfsd结尾
print(name3.endswith('dfsd'))
#判断是否已dfsd开头
print(name3.startswith('dfsd'))
#大小写转换
print(name3.upper().lower())
05-08 08:04