You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Some computer science literature uses the following notation to express assignments and to avoid the confusion with mathematical equations:</p>
13183
-
$$x \leftarrow x + 1$$<p>Let’s apply our two-step rule to the assignment <code>x = x + 1</code> given above:</p>
13184
+
<p>$$x \leftarrow x + 1$$</p>
13185
+
<p>Let’s apply our two-step rule to the assignment <code>x = x + 1</code> given above:</p>
13184
13186
<ol>
13185
13187
<li><p>Evaluate the value on the right hand side of the equal sign: for this we need to know what the current value of <code>x</code> is. Let’s assume <code>x</code> is currently <code>4</code>. In that case, the right hand side <code>x+1</code> evaluates to <code>5</code>.</p>
Copy file name to clipboardExpand all lines: html/03-data-types-structures.html
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -12535,16 +12535,17 @@ <h3 id="Functions-applicable-to-all-types-of-numbers">Functions applicable to al
12535
12535
<h2id="Sequences">Sequences<aclass="anchor-link" href="#Sequences">¶</a></h2><p>Strings, lists and tuples are <em>sequences</em>. They can be <em>indexed</em> and <em>sliced</em> in the same way.</p>
12536
12536
<p>Tuples and strings are “immutable” (which basically means we can’t change individual elements within the tuple, and we cannot change individual characters within a string) whereas lists are “mutable” (<em>.i.e</em> we can change elements in a list.)</p>
12537
12537
<p>Sequences share the following operations</p>
12538
-
<table>
12539
-
<tr><td>`a[i]`</td><td>returns *i*-th element of `a`</td></tr>
12540
-
<tr><td>`a[i:j]`</td><td>returns elements *i* up to *j* − 1</td></tr>
12541
-
<tr><td>`len(a)`</td><td>returns number of elements in sequence</td></tr>
12542
-
<tr><td>`min(a)`</td><td>returns smallest value in sequence</td></tr>
12543
-
<tr><td>`max(a)`</td><td>returns largest value in sequence</td></tr>
12544
-
<tr><td>`x in a`</td><td>returns `True` if `x` is element in `a`</td></tr>
12545
-
<tr><td>`a + b`</td><td>concatenates `a` and `b`</td></tr>
12546
-
<tr><td>`n * a`</td><td>creates `n` copies of sequence `a`</td></tr>
12547
-
</table>
12538
+
<ul>
12539
+
<li><code>a[i]</code> returns i-th element of <code>a</code></li>
12540
+
<li><code>a[i:j]</code> returns elements i up to j-1</li>
12541
+
<li><code>len(a)</code> returns number of elements in sequence</li>
12542
+
<li><code>min(a)</code> returns smallest value in sequence</li>
12543
+
<li><code>max(a)</code> returns largest value in sequence</li>
12544
+
<li><code>x in a</code> returns <code>True</code> if <code>x</code> is element in <code>a</code></li>
12545
+
<li><code>a + b</code> concatenates <code>a</code> and <code>b</code></li>
12546
+
<li><code>n * a</code> creates <code>n</code> copies of sequence <code>a</code></li>
<p>Python requires a colon (“:”) after every condition (i.e. at the of the lines starting with <code>if</code>, <code>elif</code>, <code>else</code>. Python requires the commands to be executed within each part of the if-then-else statement to be indented.</p>
11913
11913
<h3id="Indexing">Indexing<aclass="anchor-link" href="#Indexing">¶</a></h3><p>Matlab’s indexing of matrices and vectors starts a 1 (similar to Fortran), whereas Python’s indexing starts at 0 (similar to C).</p>
11914
-
<h3id="Matrices">Matrices<aclass="anchor-link" href="#Matrices">¶</a></h3><p>In Matlab, every object is a matrix. In Python, there is a specialised extension library called <code>numpy</code> (see Sec.[cha:numer-pyth-numpy]) which provides the <code>array</code> object which in turns provides the corresponding functionality. Similar to Matlab, the <code>numpy</code> object is actually based on binary libraries and execution there very fast.</p>
11914
+
<h3id="Matrices">Matrices<aclass="anchor-link" href="#Matrices">¶</a></h3><p>In Matlab, every object is a matrix. In Python, there is a specialised extension library called <code>numpy</code> (see Sec.[cha:numer-pyth-numpy]) which provides the <code>array</code> object which in turns provides the corresponding functionality. Similar to Matlab, the <code>numpy</code> object is actually based on binary libraries and execution there very fast.</p>
11915
11915
<p>There is a dedicated introduction to numpy for Matlab users available at <ahref="https://docs.scipy.org/doc/numpy-dev/user/numpy-for-matlab-users.html">https://docs.scipy.org/doc/numpy-dev/user/numpy-for-matlab-users.html</a>.</p>
0 commit comments