Python学习3:字符串操作

来源:互联网 发布:测量编程视频教学 编辑:程序博客网 时间:2024/06/06 06:36

所有programer开发的语言Index都是0开始;
所有programer开发的语言都是左闭右开。

字符串操作

pystr = 'Python'print pystrprint pystr[:]  #代表所有print pystr[0:3]    #第0,1,2print pystr[1:3]    #第1,2print pystr[1:]     #第2及以后print pystr[:1]     #第0print pystr[-1]     #最后一个print '#' * 20      #打印20个isCool = 'is cool'print pystr + isCool + '!'print pystr * 2print '#' * 20pystr = 100print  pystr * 2print '%d is cool' % pystr      #这里的d s f x o 等和C语言一致print '%s is cool' % pystrprint '%f is cool' % pystrprint '%x is cool' % pystrprint '%o is cool' % pystrprint '%c is cool' % pystrprint str(pystr)+' is cool'     #可以用str()转化为字符串print '#' * 20

结果如下:

PythonPythonPytytythonPn####################Pythonis cool!PythonPython####################200100 is cool100 is cool100.000000 is cool64 is cool144 is coold is cool100 is cool####################Process finished with exit code 0
原创粉丝点击