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')
原文地址:https://www.cnblogs.com/why168888/p/6407977.html