##字符串操作
#字符串截取
s = "hello"
print(s[0:3])
print(s[:])
#截取全部字符
print(s[::-1])
#截取反转
#去空格
s=" hel lo "print(s)
print(s.strip())
#只去左右空格
print(s.lstrip())#去左空格
print(s.rstrip())#去右
#字符串复制
s = "hello"
s_copy = s #位置一样
print(id(s))
print(id(s_copy))
s = s.title()#新建一空间放改变的s,s_copy不变
print(s)
print(s_copy)
#字符串拼接
s = "hello"
s1 = "python"
#s2 = s+s1#方法一
#print(s2)
#法二
import operator
s2 = operator.concat(s,s1)
print(s2)
#按照字母的阿斯克码ASCII的大小比较a最小z最大
#lt(a, b) ———— 小于
#le(a, b) ———— 小于等于
#eq(a, b) ———— 等于
#ne(a, b) ———— 不等于
#ge(a, b) ———— 大于等于
#gt(a, b) ———— 大于
b = operator.lt(s,s1)
print(b)
print(s<s1)
#求字符串的长度
print(len(s),len(s1))
#求字符串中最大,最小字符
print(max(s))
print(min(s1))
#字符串大小写转换
#upper ———— 转换为大写
#lower ———— 转换为小写
#title ———— 转换为标题(每个单词首字母大写)
#capitalize ———— 首字母大写
#swapcase ———— 大写变小写,小写变大写
eg
s = "helloASed how are you"
print(s.upper())#大写
print(s.lower())#小写
print(s.title())#所以首字母大写
print(s.capitalize())#第一个首字母大写
print(s.swapcase())#大转小,小转大
#字符串分割
s = "helloASed how are you"
ss = s.split("o")#以o拆分,啥不写 默认按空格拆分
print(ss)
#字符串序列连接
s = "helloASed how are you"
s1 = "sdfre"
s2 = s.join(s1)
print(s2)
#join用法
a = ['hello','world']
str ="-"
print(str.join(a))
#字符串查找 find方法
s1 = 'today is a fine day'
index = s1.find("is",6,8)#6起始位置,8终止位置,查不到返回-1
print(index)
#字符串内替换
s1= 'today is a fine day is is is is'
s = s1.replace("is","are",2)#写2,只替换前两个
print(s,s1)
#字符串判断
#isdigit ———— 检测字符串时候只由数字组成
#isalnum ———— 检测字符串是否只由数字和字母组成
#isalpha ———— 检测字符串是否只由字母组成
#islower ———— 检测字符串是否只含有小写字母
#isupper ———— 检测字符串是否只含有大写字母
#isspace ———— 检测字符串是否只含有空格
#istitle ———— 检测字符串是否是标题(每个单词首字母大写)
s = " "
print(s.isspace())#只打印空格,有别的, 结果为alse
s = " d "
print(s.isspace())# 结果为false