print'索引操作'
tuple=("apple","banana","grape","orange") #元组,列表,字符串统称为序列
list=["apple","banana","grape","orange"]
str="apple"
print tuple[0]
print tuple[-1]
print list[0]
print list[-1]
print str[0]
print str[-1]
print
print'分片操作'
tuple=("apple","banana","grape","orange")
list=["apple","banana","grape","orange"]
str="apple"
print tuple[:3]
print tuple[3:]
print tuple[1:-1]
print tuple[:]
print
print list[:3]
print list[3:]
print list[1:-1]
print list[:]
print
print str[:3]
print str[3:]
print str[1:-1]
tuple=("apple","banana","grape","orange") #元组,列表,字符串统称为序列
list=["apple","banana","grape","orange"]
str="apple"
print tuple[0]
print tuple[-1]
print list[0]
print list[-1]
print str[0]
print str[-1]
print'分片操作'
tuple=("apple","banana","grape","orange")
list=["apple","banana","grape","orange"]
str="apple"
print tuple[:3]
print tuple[3:]
print tuple[1:-1]
print tuple[:]
print list[:3]
print list[3:]
print list[1:-1]
print list[:]
print str[:3]
print str[3:]
print str[1:-1]
print str[:]
====================== RESTART: C:/Python27/sequence.py ======================
索引操作
apple
orange
apple
orange
a
e
分片操作
('apple', 'banana', 'grape')
('orange',)
('banana', 'grape')
('apple', 'banana', 'grape', 'orange')
['apple', 'banana', 'grape']
['orange']
['banana', 'grape']
['apple', 'banana', 'grape', 'orange']
app
le
ppl
apple