立即学习:https://edu.csdn.net/course/play/26676/338776?utm_source=blogtoedu
查看对象的属性用dir函数dir()
例:查看字符串(str)的属性和方法
dir(str)
查看字符串的方法用:help(s或str.index)
str的index方法用法:
a='my name is'
a
'my name is'
>>> a.index('e')
6
split(分割、分裂)用法
a='i love you'
a
'i love you'
>>> a.split(' ')
['i', 'love', 'you']
jion(连接)用法
lst=['i', 'love', 'you']
>>> lst
['i', 'love', 'you']
>>> ' '.join(lst)
'i love you'
---------------------------------------------
字符串格式化输出format(格式)
>符号是右对其
^符号是居中
interest='i love {0} and {1}'
>>> interest.format('python','football')
'i love python and football'
i='i love {0:^10} and {1:>10}'
>>> i.format('python','football')
'i love python and football'
------------------------------------------
字符串对数字的格式化输出,例:
'he is {0:2d} years old and {1:.2f}m in height'.format(33,1.65)
'he is 33 years old and 1.65m in height'