Difference normal quote and backquote in python

If i write

a=eval('[[0]*2]*2')
a[0][0]=1

a will become [[1,0],[1,0]]

If i write

a=eval(`[[0]*2]*2`)
a[0][0]=1

a will become [[1,0],[0,0]]

Can someone tell me why?

+5
source share
2 answers
>>> '[[0]*2]*2'
'[[0]*2]*2'

>>> `[[0]*2]*2`
'[[0, 0], [0, 0]]'

The first is text, the second is immediately in the data structure and returns its textual representation '[[0, 0], [0, 0]]'.

The problem with this [[0]*2]*2is that it refers to a list of links to the same object. That is why you get [[1,0],[1,0]], not [[1,0],[0,0]].

+14
source
eval('[[0]*2]*2')

Python [[0]*2]*2. . [x, x], x , [0, 0]. , .

eval(`[[0]*2]*2`)

( [[0]*2]*2), (- ), [[0, 0], [0, 0]], Python. - , [0, 0], . , .

BTW, ``, . ``. Python.

`hi mom`

.

+5

All Articles