Python学习3:字符串操作

所有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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值