String Slice : String Slice « String « Python






String Slice

String Slice

begin = 2
end   = 5
word="a long word"

print "word[", begin, ":", end, "]\t\t",
print word[begin:end]

           
       








Related examples in the same category

1.String slicing: extrace sectionString slicing: extrace section
2.Strings can be subscripted (indexed)Strings can be subscripted (indexed)
3.An invariant of slice operations: s[:i] + s[i:] equals sAn invariant of slice operations: s[:i] + s[i:] equals s
4.Degenerate slice indicesDegenerate slice indices
5.Negative Indices numbers: start counting from the rightNegative Indices numbers: start counting from the right