# -7654321
# 0123456
world = "abcdefg";
a = world[2];
print "a is " + a; #c
b = world[1:3];
print "b is " + b; #bc
c = world[:2];
print "c is " + c; #ab
d = world[0:];
print "d is " + d; #abcdefg
e = world[:2] + world[2:];
print "e is " + e; #abcdefg
f = world[-1];
print "f is " + f; #g
g = world[-4 : -2];
print "g is " + g; #de
h = world[-2:];
print "h is " + h; #fg
i = world[:-2];
print "i is " + i; #abcde
l = len(world);
print "l is " + str(l); #7
【python摘录01】字符串
最新推荐文章于 2022-03-21 14:58:22 发布