# name: pshdhx
# time:2021/2/10 14:20
# == 判断字符串的值,is 判断字符串的地址
# 当字符串中有%号时,它的地址是不同的
# 符合标志符号的字符串,地址不同
# 字符串只在编辑时驻留,而非运行时
# [-5,256]之间的整数数字,地址相同,超出了,地址不同
a='abc'
b='ab'+'c'
c=''.join(['ab','c'])
print(a,type(a))
print(b,type(b))
print(c,type(c))
print(a is b)
print(a is c) #false
print(b is c) #false

# a和b都是程序运行前组装好的,c是程序运行中组装好的
import sys
a='abc%'
b='abc%'
a=sys.intern(b)
print(a is b)


#字符串查询操作
s='hello hello'
# 查找第一个
print(s.index('lo')) #3
print(s.find('lo')) #3
# 查找最后一个
print(s.rindex('lo')) #9 逆向索引,从-1开始,从右边到左边
print(s.rfind('lo')) #9
#用index如果没有会超出索引,抛出异常,使用find则会-1

# 字符串中的大小写转换
s='hello world'
a=s.upper()
print(a)
# 使用low和super的id不一样
# swapcase() 大写变小写,小写变大写
# capitalize把第一个字符转为大写,其余字符转为小写
# title把每个单词的第一个字符转为大写,剩余单词转为小写

#字符串内容对齐
s='hello,Python'
print(s.center(20,'*'))
print(s.ljust(20,'*')) #默认是填充空格

# 右对齐,使用0进行填充
print(s.zfill(20))

# 字符串分割,返回值是列表
print(s.split(','))

s='hello|pshdhx|learn|python'
print(s.split(sep="|",maxsplit=2)) #只分割前两个字符串
# rsplit 是从右边开始分割

lst=['hello','python','pshdhx']
print(','.join(lst))

name='pshdhx'
age=24
print('我叫%s,今年%d岁' % (name,age))
print('我叫{0},今年{1}岁'.format(name,age))
print(f'我叫{name},今年{age}岁')
print('%10d'% 99999) #10是宽度
print('%.3f' % 3.1415926)
print('%10.3f' % 3.1415926)


print(3.1415926)
print('{}'.format(3.1415926))
print('{0:.3}'.format(3.1415)) #是一共三位数,而不是三位小数
print('{0:.3f}'.format(3.1415))

print('你好')
print('你好'.encode(encoding='GBK')) #二进制,GBK一个汉字两个字节
print('你好'.encode(encoding='UTF-8')) #二进制,UTF一个汉字两个字节