`
wait_miracle
  • 浏览: 19564 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

python-字符串

 
阅读更多

word="abcdefg"
a=word[2]
print "a is: "+a
b=word[1:3]
print "b is: "+b # index 1 and 2 elements of word.
c=word[:2]
print "c is: "+c # index 0 and 1 elements of word.
d=word[0:]
print "d is: "+d # All elements of word.
e=word[:2]+word[2:]
print "e is: "+e # All elements of word.
f=word[-1]
print "f is: "+f # The last elements of word.
g=word[-4:-2]
print "g is: "+g # index 3 and 4 elements of word.
h=word[-2:]
print "h is: "+h # The last two elements.
i=word[:-2]
print "i is: "+i # Everything except the last two characters
l=len(word)
print "Length of word is: "+ str(l)

 

 

a is: c
b is: bc
c is: ab
d is: abcdefg
e is: abcdefg
f is: g
g is: de
h is: fg
i is: abcde
Length of word is: 7

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics