>>> s = 'hello,world!'
>>> len(s)
12
>>> s.capitalize()
'Hello,world!'
>>> s.upper()
'HELLO,WORLD!'
>>> s.find('or')
7
>>> s.find('shi')
-1
>>> s.startswith('he')
True
>>> s.endswith('!')
True
>>> s.center(50,'*')
'*******************hello,world!*******************'
>>> s.rjust(50,' ')
' hello,world!'
>>> a = 'abc123456'
>>> a[2]
'c'
>>> a[2:5]
'c12'
>>> a[2:]
'c123456'
>>> a[::2]
'ac246'
>>> a[2::2]
'c246'
>>> a[-3:-1]
'45'
>>> a.isalpha()
False
>>> a.isalnum()
True
>>> a.strip()
'abc123456'
f = [x ** 2 for x in range(1, 1000)] print(sys.getsizeof(f)) # 查看对象占用内存的字节数 print(f) f = (x ** 2 for x in range(1, 1000)) print(sys.getsizeof(f)) # 相比生成式生成器不占用存储数据的空间 print(f)