- 字符串驻留机制(地址)
- 查询 推荐.find() .rfind()
- 大小写转换 .upper() .lower() .swapcase() .capitalize() .title()
- 内容对齐 .center() .ljust() .rjust() .zfill()
- 劈分 .split() .rsplit()
- 字符串内容判断 .isidentifier() .isspace() .isalpha() .isdecimal() .isnumeric() .isalnum()
- 替换 .replace()
- 合并 .join()
- 比较 >< ord(字符) chr(ascii码值)
- 切片 [start,end,step]
- 格式化字符串 %占位符, {}占位符
- 字符编码 .encode() .encode()
a = 'python'
b = "python"
c = '''python'''
print(id(a))
print(id(b))
print(id(c))
s = 'hello,hello'
print(s.index('lo'))
print(s.find('lo'))
print(s.rindex('lo'))
print(s.rfind('lo'))
print(s.find('k'))
print(s.rfind('k'))
s = 'Hello,World'
print(id(s))
a = s.upper()
print(a,id(a))
b = s.lower()
print(b)
c = s.swapcase()
print(c)
d = s.capitalize()
print(d)
e = s.title()
print(e)
s = 'hello,Python'
print(s.center(20,'*'))
print(s.ljust(20,'^'))
print(s.rjust(20))
print(s.zfill(20))
print(s.ljust(5))
print('-233'.zfill(8))
s = 'hello world Python'
s1 = 'hello|world|Python'
print(s.split())
print(s1.split(sep='|'))
print(s1.split(sep='|',maxsplit=1))
print(s.rsplit(maxsplit=1))
print('1,','hello,world'.isidentifier())
print('1,','张三2_'.isidentifier())
print('2,','\t'.isspace())
print('3,','hhh'.isalpha())
print('3,','张三'.isalpha())
print('3,','张三2'.isalpha())
print('4,','101'.isdecimal())
print('4,','ⅠⅡⅣ'.isdecimal())
print('4,','八八六'.isdecimal())
print('5,','ⅠⅡⅣ'.isnumeric())
print('5,','八八六'.isnumeric())
print('6,','ab78张'.isalnum())
print('6,','!。'.isalnum())
s = 'hello Python Python Python'
print(s.replace('Python','Java'))
print(s.replace('Python','Java',2))
print('*'.join('Python'))
lst = ['hello','Python','world']
print('|'.join(lst))
t = ('hello','Python','world')
print(''.join(t))
print('apple' > 'app')
print('apple' < 'banana')
print(ord('a'), ord('b'))
print(chr(97), chr(98))
s = 'hello,Python'
s1 = s[:5]
s2 = s[6:]
s3 = '!'
newstr = s1+s3+s2
print(newstr)
print(id(s))
print(id(s1))
print(id(s2))
print(id(s3))
print(id(newstr))
s = '0123456789'
print(s[1:9:2])
print(s[::2])
print(s[::-2])
s = 'hello,Python'
print(s[-6::1])
name = '张三'
age = 21
print('我叫%s,今年%i周岁' % (name,age))
print('我叫{0},今年{1}周岁'.format(name,age))
print(f'我叫{name},今年{age}周岁')
print('%10f' % 3.1415926)
print('%10.3f' % 3.1415926)
print('%-10.3f' % 3.1415926)
print('{0}'.format(3.1415926))
print('{:.3}'.format(3.1415926))
print('{:.3f}'.format(3.1415926))
print('{:10.3}'.format(3.1415926))
s = '天涯共此时'
print(s.encode(encoding='GBK'))
print(s.encode(encoding='UTF-8'))
byte = s.encode(encoding='GBK')
print(byte.decode(encoding='GBK'))
|