In earlier years, i had find that:
# Python code
x = [[0]*5]*5 # IMO, it will be a 5*5 2D-Array-Like
x[2][2] = 2
# I considered x will be
# [
# [0,0,0,0,0],
# [0,0,0,0,0],
# [0,0,2,0,0],
# [0,0,0,0,0],
# [0,0,0,0,0]]
# But x will be
# [
# [0,0,2,0,0],
# [0,0,2,0,0],
# [0,0,2,0,0],
# [0,0,2,0,0],
# [0,0,2,0,0]]
So, why? Of course, later i had known this is because references of inner list. I do not thinks it is a good idea.
But again:
x[:][4] = 4
IMO again:
x[:] must be x's self. x[:][4] must be the last member of x. So x will be:
#[
# [0,0,2,0,0],
# [0,0,2,0,0],
# [0,0,2,0,0],
# [0,0,2,0,0],
# 4]
But it is not, there is no change!
So, why?
And, are there any other wired cases in Python? Please show below.
I just wanna collect things looks a bit strange in Python, not just a quizzer about this question.