<p>It seems like the code is from <a href="https://arxiv.org/pdf/1305.1878.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1305.1878.pdf</a> (Apendix A).</p>
<p>First, the backticks in the code are actually <code>'</code>. I guess the paper prints backticks just because the journal (or the authors) didn't handle the character properly.</p>
<p>Now <code>not i:2 if i==2 else None:2 if i==1 else 1</code> is just a slicing like what <code>A[...:...:...]</code> would mean for example.</p>
<p><code>x if a else y</code> is what's called <a href="https://docs.python.org/3/reference/expressions.html#conditional-expressions" rel="nofollow noreferrer">conditional expression</a>; it evaluates to <code>x</code> if <code>a</code> is true, and <code>y</code> otherwise.</p>
<p>So, for example, if <code>i == 1</code>, then</p>
<ol>
<li><code>not i</code> becomes <code>False</code>, since <code>1</code> is Truthy.</li>
<li><code>2 if i == 2 else None</code> becomes <code>None</code>.</li>
<li><code>2 if i == 1 else 1</code> becomes <code>2</code>.</li>
</ol>
<p>So <code>not i:2 if i==2 else None:2 if i==1 else 1</code> in this case becomes <code>False:None:2</code>, which is <code>0::2</code> when used as a slice. Likewise, when <code>j == 1</code>, the second one <code>not j:2 if j==2 else None:2 if j==1 else 1</code> becomes <code>0::2</code>. Therefore <code>a = A[::2, ::2]</code> if <code>i == 1, j == 2</code>.</p>
<p>An example follows:</p>
<pre class="lang-py prettyprint-override"><code>import numpy as np

def cofactor(A, ij):
    '''Cofactor[i,j] of 3x3 matrix A'''
    i, j = ij
    a = A[not i:2 if i==2 else None:2 if i==1 else 1,
          not j:2 if j==2 else None:2 if j==1 else 1] 
    return (-1)**(i+j) * (a[0,0]*a[1,1] - a[1,0]*a[0,1])

A = np.arange(9).reshape(3, 3) # an example matrix; [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
print(cofactor(A, (1, 2))) # 6
</code></pre>
<p>Note that I modified the function a little bit; apparently, defining a function with arguments <code>(A, (i, j))</code> as in the paper is not a valid syntax. So I added a line to explicitly unpack the tuple <code>ij</code> into <code>i</code> and <code>j</code>.</p>
How to access list and matrix using if and how to use a defined function?
<p>I am confused by the python code mentioned below. What does the statement <code>not i:2 if i==2 else None:2 if i==1 else 1</code> mean?
Besides, how can I use the function <code>cofactor(A, (i, j))</code>; can you give an example?</p>
<pre><code>def cofactor(A, (i, j)):
    ’’’Cofactor[i,j] of 3x3 matrix A’’’
    a = A[not i:2 if i==2 else None:2 if i==1 else 1,
          not j:2 if j==2 else None:2 if j==1 else 1] 
    return (-1)**(i+j) * (a[0,0]*a[1,1] - a[1,0]*a[0,1])
</code></pre>