你所不了解的python小tips

python是很友好的语言,但是有时也有一些小烦恼,

s = 'spam'
s[:0]    # => ''

s[0][0][0] # => 's'

[[]]  # => [[]]

n = [1,2,3,4,5]
n[3:1] = ['?']  # => [1, 2, 3, '?', 4, 5]

#当赋值非序列给分片时
n[2:3] = 1
TypeError: can only assign an iterable


d = {}
d[(1,2,3)] = 1
d  # => {(1,2,3):1} 

你可能感兴趣的:(你所不了解的python小tips)