Loading

Python切片(入门7)

转载请标明出处:
http://www.cnblogs.com/why168888/p/6407977.html

本文出自:【Edwin博客园】


Python切片

1. 对list进行切片

L = range(1, 101)
print L[:10]
print L[2::3]
print L[4:50:5]

2. 倒序切片

L = range(1, 101)
print L[-10:]
print L[-46::5]

3. 对字符串切片

def firstCharUpper(s):
    return s[0].upper() + s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
posted @ 2017-02-17 11:12  浩友  阅读(216)  评论(0编辑  收藏  举报