所有programer开发的语言Index都是0开始;
所有programer开发的语言都是左闭右开。
字符串操作
pystr = 'Python'
print pystr
print pystr[:] #代表所有
print pystr[0:3] #第0,1,2
print pystr[1:3] #第1,2
print pystr[1:] #第2及以后
print pystr[:1] #第0
print pystr[-1] #最后一个
print '#' * 20 #打印20个
isCool = 'is cool'
print pystr + isCool + '!'
print pystr * 2
print '#' * 20
pystr = 100
print pystr * 2
print '%d is cool' % pystr #这里的d s f x o 等和C语言一致
print '%s is cool' % pystr
print '%f is cool' % pystr
print '%x is cool' % pystr
print '%o is cool' % pystr
print '%c is cool' % pystr
print str(pystr)+' is cool' #可以用str()转化为字符串
print '#' * 20
结果如下:
Python
Python
Pyt
yt
ython
P
n
####################
Pythonis cool!
PythonPython
####################
200
100 is cool
100 is cool
100.000000 is cool
64 is cool
144 is cool
d is cool
100 is cool
####################
Process finished with exit code 0