Slice a string : slice « String « Python Tutorial

Home
Python Tutorial
1.Introduction
2.Data Type
3.Statement
4.Operator
5.String
6.Tuple
7.List
8.Dictionary
9.Collections
10.Function
11.Class
12.File
13.Buildin Function
14.Buildin Module
15.Database
16.Regular Expressions
17.Thread
18.Tkinker
19.wxPython
20.XML
21.Network
22.CGI Web
23.Windows
Python Tutorial » String » slice 
5.29.1.Slice a string
pystr = 'Python'
iscool = 'is cool!'
print pystr[0]
print pystr[2:5]
print iscool[:2]
print iscool[3:]
print iscool[-1]
5.29.slice
5.29.1.Slice a string
5.29.2.How to Access Values (Characters and Substrings) in Strings
5.29.3.for any ranges [start:end], we get all characters starting at offset start up to, but not including, the character at end.
5.29.4.When either a starting or an ending index is missing, they default to the beginning or end of the string, respectively.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.