Repository navigation
Expand file tree
/
Copy pathVariables_and_Assignment.html
More file actions
507 lines (359 loc) · 25.7 KB
/
Copy pathVariables_and_Assignment.html
File metadata and controls
507 lines (359 loc) · 25.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Variables & Assignment — Python Like You Mean It 0.9.1 documentation</title>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/my_theme.css" type="text/css" />
<link rel="index" title="Index"
href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="Python Like You Mean It 0.9.1 documentation" href="../index.html"/>
<link rel="up" title="Module 2: The Essentials of Python" href="../module_2.html"/>
<link rel="next" title="Introducing Control Flow" href="Introduction.html"/>
<link rel="prev" title="Sequence Types" href="SequenceTypes.html"/>
<script src="../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="../index.html" class="icon icon-home"> Python Like You Mean It
</a>
<div class="version">
0.9.1
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Table of Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../intro.html">Python Like You Mean It</a></li>
<li class="toctree-l1"><a class="reference internal" href="../module_1.html">Module 1: Getting Started with Python</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../module_2.html">Module 2: The Essentials of Python</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="Basic_Objects.html">Basic Object Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="SequenceTypes.html">Sequence Types</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Variables & Assignment</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#Valid-Names-for-Variables">Valid Names for Variables</a></li>
<li class="toctree-l3"><a class="reference internal" href="#Referencing-a-Mutable-Object-with-Multiple-Variables">Referencing a Mutable Object with Multiple Variables</a></li>
<li class="toctree-l3"><a class="reference internal" href="#Mutable-&-Immutable-Types-of-Objects">Mutable & Immutable Types of Objects</a></li>
<li class="toctree-l3"><a class="reference internal" href="#Reading-Comprehension-Exercise-Solutions:">Reading Comprehension Exercise Solutions:</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="Introduction.html">Introducing Control Flow</a></li>
<li class="toctree-l2"><a class="reference internal" href="ConditionalStatements.html">Conditional Statements</a></li>
<li class="toctree-l2"><a class="reference internal" href="ForLoops.html">For-Loops and While-Loops</a></li>
<li class="toctree-l2"><a class="reference internal" href="Iterables.html">Iterables</a></li>
<li class="toctree-l2"><a class="reference internal" href="Generators_and_Comprehensions.html">Generators & Comprehension Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="Itertools.html">Python’s “Itertools”</a></li>
<li class="toctree-l2"><a class="reference internal" href="Functions.html">Basics of Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="Scope.html">Scope</a></li>
<li class="toctree-l2"><a class="reference internal" href="DataStructures.html">Data Structures (Part I): Introduction</a></li>
<li class="toctree-l2"><a class="reference internal" href="DataStructures_II_Dictionaries.html">Data Structures (Part II): Dictionaries</a></li>
<li class="toctree-l2"><a class="reference internal" href="DataStructures_III_Sets_and_More.html">Data Structures (Part III): Sets & the Collections Module</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../module_3.html">Module 3: The Essentials of NumPy</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">Python Like You Mean It</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html">Docs</a> »</li>
<li><a href="../module_2.html">Module 2: The Essentials of Python</a> »</li>
<li>Variables & Assignment</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/Module2_EssentialsOfPython/Variables_and_Assignment.ipynb.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<style>
/* CSS overrides for sphinx_rtd_theme */
/* 24px margin */
.nbinput.nblast,
.nboutput.nblast {
margin-bottom: 19px; /* padding has already 5px */
}
/* ... except between code cells! */
.nblast + .nbinput {
margin-top: -19px;
}
/* nice headers on first paragraph of info/warning boxes */
.admonition .first {
margin: -12px;
padding: 6px 12px;
margin-bottom: 12px;
color: #fff;
line-height: 1;
display: block;
}
.admonition.warning .first {
background: #f0b37e;
}
.admonition.note .first {
background: #6ab0de;
}
.admonition > p:before {
margin-right: 4px; /* make room for the exclamation icon */
}
</style>
<div class="section" id="Variables-&-Assignment">
<h1>Variables & Assignment<a class="headerlink" href="#Variables-&-Assignment" title="Permalink to this headline">¶</a></h1>
<div class="admonition warning">
<p class="first fa fa-exclamation-circle"><strong>Note</strong>:</p>
<p class="last">There are reading-comprehension exercises included throughout the text.
These are meant to help you put your reading to practice. Solutions for
the exercises are included at the bottom of this page.</p>
</div>
<p>Variables permit us to write code that is flexible and amendable to
repurpose. Suppose we want to write code that logs a student’s grade on
an exam. The logic behind this process should not depend on whether we
are logging Brian’s score of 92% versus Ashley’s score of 94%. As such,
we can utilize variables, say <code class="docutils literal"><span class="pre">name</span></code> and <code class="docutils literal"><span class="pre">grade</span></code>, to serve as
placeholders for this information. In this subsection, we will
demonstrate how to define variables in Python.</p>
<p>In Python, the <code class="docutils literal"><span class="pre">=</span></code> symbol represents the “assignment” operator. The
variable goes to the left of <code class="docutils literal"><span class="pre">=</span></code>, and the object that is being
assigned to the variable goes to the right:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">name</span> <span class="o">=</span> <span class="s2">"Brian"</span> <span class="c1"># the variable `name` is being assigned the string "Brian"</span>
<span class="n">grade</span> <span class="o">=</span> <span class="mi">92</span> <span class="c1"># the variable `grade` is being assigned the integer 92</span>
</pre></div>
</div>
<p>Attempting to reverse the assignment order (e.g. <code class="docutils literal"><span class="pre">92</span> <span class="pre">=</span> <span class="pre">name</span></code>) will
result in a syntax error. When a variable is assigned an object (like a
number or a string), it is common to say that the variable
<strong>references</strong> that object. That is, the variable <code class="docutils literal"><span class="pre">name</span></code> references
the string <code class="docutils literal"><span class="pre">"Brian"</span></code>.</p>
<p>Once a variable is referencing a value, you can use the variable
elsewhere in your code as a placeholder:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># demonstrating the use of variables in code</span>
<span class="n">name</span> <span class="o">=</span> <span class="s2">"Brian"</span>
<span class="n">grade</span> <span class="o">=</span> <span class="mi">92</span>
<span class="n">failing</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">if</span> <span class="n">grade</span> <span class="o"><</span> <span class="mi">60</span><span class="p">:</span>
<span class="n">failing</span> <span class="o">=</span> <span class="bp">True</span>
<span class="c1"># writes: name | grade | passing-status</span>
<span class="c1"># to the end of the file "student_grades.txt"</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"student_grades.txt"</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s2">"a"</span><span class="p">)</span> <span class="k">as</span> <span class="n">opened_file</span><span class="p">:</span>
<span class="n">opened_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">f</span><span class="s2">"{name} | {grade} | {failing}"</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="Valid-Names-for-Variables">
<h2>Valid Names for Variables<a class="headerlink" href="#Valid-Names-for-Variables" title="Permalink to this headline">¶</a></h2>
<p>A variable name can only consist of alphanumeric characters (<code class="docutils literal"><span class="pre">a-z</span></code>,
<code class="docutils literal"><span class="pre">A-Z</span></code>, <code class="docutils literal"><span class="pre">0-9</span></code>) and the underscore symbol (<code class="docutils literal"><span class="pre">_</span></code>); a valid name cannot
begin with a numerical value:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">var</span></code>: valid</li>
<li><code class="docutils literal"><span class="pre">_var2</span></code>: valid</li>
<li><code class="docutils literal"><span class="pre">ApplePie_Yum_Yum</span></code>: valid</li>
<li><code class="docutils literal"><span class="pre">2cool</span></code>: <strong>invalid</strong> (begins with a numerical character)</li>
<li><code class="docutils literal"><span class="pre">I.am.the.best</span></code>: <strong>invalid</strong> (contains <code class="docutils literal"><span class="pre">.</span></code>)</li>
</ul>
<p>They also cannot conflict with character sequences that are reserved by
the Python language. As such, the following cannot be used as variable
names:</p>
<ul class="simple">
<li>for, while, break, pass, continue</li>
<li>in, is, not</li>
<li>if, else, elif</li>
<li>def, class, return, yield, raises</li>
<li>import, from, as, with</li>
<li>try, except, finally</li>
</ul>
</div>
<div class="section" id="Referencing-a-Mutable-Object-with-Multiple-Variables">
<h2>Referencing a Mutable Object with Multiple Variables<a class="headerlink" href="#Referencing-a-Mutable-Object-with-Multiple-Variables" title="Permalink to this headline">¶</a></h2>
<p>It is possible to assign variables to other, existing variables. Doing
so will cause the variables to reference the same object:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># demonstrating the behavior of variables</span>
<span class="c1"># referencing the same object</span>
<span class="o">>>></span> <span class="n">list1</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> <span class="c1"># `list1` references [1, 2, 3]</span>
<span class="o">>>></span> <span class="n">list2</span> <span class="o">=</span> <span class="n">list1</span> <span class="c1"># `list2` and `list1` now both reference [1, 2, 3]</span>
<span class="o">>>></span> <span class="k">print</span><span class="p">(</span><span class="n">list1</span><span class="p">)</span>
<span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
<span class="o">>>></span> <span class="k">print</span><span class="p">(</span><span class="n">list2</span><span class="p">)</span>
<span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
</pre></div>
</div>
<p>What this entails is that these common variables will reference the
<em>same instance</em> of the list. Meaning that if the list changes, all of
the variables referencing that list will reflect this change:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">list1</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="c1"># append 4 to the end of [1, 2, 3]</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">list1</span><span class="p">)</span>
<span class="go">[1, 2, 3, 4]</span>
</pre></div>
</div>
<p>We can see that <code class="docutils literal"><span class="pre">list2</span></code> is still assigned to reference the <em>same,
updated</em> list as <code class="docutils literal"><span class="pre">list1</span></code>:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">list2</span><span class="p">)</span>
<span class="go">[1, 2, 3, 4]</span>
</pre></div>
</div>
<p>In general, assigning a variable <code class="docutils literal"><span class="pre">b</span></code> to a variable <code class="docutils literal"><span class="pre">a</span></code> will cause
the variables to reference the <em>same</em> object in the system’s memory, and
assigning <code class="docutils literal"><span class="pre">c</span></code> to <code class="docutils literal"><span class="pre">a</span></code> or <code class="docutils literal"><span class="pre">b</span></code> will simply have a third variable
reference this same object. Then any change (a.k.a <em>mutation</em>) of the
object will be reflected in all of the variables that reference it
(<code class="docutils literal"><span class="pre">a</span></code>, <code class="docutils literal"><span class="pre">b</span></code>, and <code class="docutils literal"><span class="pre">c</span></code>).</p>
<p>Of course, assigning two variables to identical but <em>distinct</em> lists
means that a change to one list will not affect the other:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">list1</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> <span class="c1"># `list1` references [1, 2, 3]</span>
<span class="gp">>>> </span><span class="n">list2</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span> <span class="c1"># `list2` references a *separate* list, whose value is [1, 2, 3]</span>
<span class="gp">>>> </span><span class="n">list1</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="c1"># append 4 to the end of [1, 2, 3]</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">list1</span><span class="p">)</span>
<span class="go">[1, 2, 3, 4]</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">list2</span><span class="p">)</span> <span class="c1"># `list2` still references its own list</span>
<span class="go">[1, 2, 3]</span>
</pre></div>
</div>
<hr class="docutils" />
<p><strong>Reading Comprehension: Does slicing a list produce a reference to that
list?</strong></p>
<p>Suppose <code class="docutils literal"><span class="pre">x</span></code> is assigned a list, and that <code class="docutils literal"><span class="pre">y</span></code> is assigned a “slice”
of <code class="docutils literal"><span class="pre">x</span></code>. Do <code class="docutils literal"><span class="pre">x</span></code> and <code class="docutils literal"><span class="pre">y</span></code> reference the same list? That is, if you
update part of the subsequence common to <code class="docutils literal"><span class="pre">x</span></code> and <code class="docutils literal"><span class="pre">y</span></code>, does that
change show up in both of them? Write some simple code to investigate
this.</p>
<hr class="docutils" />
<p>This discussion is warranted for a list, because a list is <em>mutable</em> - a
given list can be changed after it is created. A tuple, being
<em>immutable</em>, cannot be changed. Any operation that appears to be
updating a tuple must actually be creating an entirely new tuple
altogether. Consider the following example:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># `x` and `y` reference the same tuple</span>
<span class="o">>>></span> <span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">y</span> <span class="o">=</span> <span class="n">x</span>
<span class="c1"># shorthand for: x = x + (4, 5)</span>
<span class="c1"># this creates a new tuple</span>
<span class="o">>>></span> <span class="n">x</span> <span class="o">+=</span> <span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">x</span>
<span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="c1"># y still references the original tuple</span>
<span class="o">>>></span> <span class="n">y</span>
<span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="Mutable-&-Immutable-Types-of-Objects">
<h2>Mutable & Immutable Types of Objects<a class="headerlink" href="#Mutable-&-Immutable-Types-of-Objects" title="Permalink to this headline">¶</a></h2>
<p>The following are some common immutable and mutable objects in Python.
These will be important to have in mind as we start to work with
dictionaries and sets.</p>
<p><strong>Some immutable objects</strong></p>
<ul class="simple">
<li>numbers (integers, floating-point numbers, complex numbers)</li>
<li>strings</li>
<li>tuples</li>
<li>boolean values</li>
<li>“frozen”-sets</li>
</ul>
<p><strong>Some mutable objects</strong></p>
<ul class="simple">
<li>lists</li>
<li>dictionaries</li>
<li>sets</li>
<li>NumPy arrays</li>
</ul>
<hr class="docutils" />
<p><strong>Reading Comprehension: Understanding References</strong></p>
<p>Based on our discussion of mutable and immutable objects, predict what
the value of <code class="docutils literal"><span class="pre">y</span></code> will be in the following circumstance:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span>
<span class="go"># shorthand for: `x = x * 3`</span>
<span class="gp">>>> </span><span class="n">x</span> <span class="o">*=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">x</span>
<span class="go">9</span>
<span class="gp">>>> </span><span class="n">y</span>
<span class="go">???</span>
</pre></div>
</div>
<hr class="docutils" />
</div>
<hr class="docutils" />
<div class="section" id="Reading-Comprehension-Exercise-Solutions:">
<h2>Reading Comprehension Exercise Solutions:<a class="headerlink" href="#Reading-Comprehension-Exercise-Solutions:" title="Permalink to this headline">¶</a></h2>
<p><strong>Does slicing a list produce a reference to that list?: Solution</strong></p>
<p>Based on the following behavior, we can conclude that slicing a list
does <strong>not</strong> produce a reference to the original list. Rather, slicing a
list produces a copy of the appropriate subsequence of the list:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">y</span> <span class="c1"># does `y` reference the same list as `x`?</span>
<span class="go">[0, 1]</span>
<span class="go">x[0] = -1 # update one of the entries of the list that `x` references</span>
<span class="gp">>>> </span><span class="n">x</span>
<span class="go">[-1, 1, 2, 3]</span>
<span class="gp">>>> </span><span class="n">y</span> <span class="c1"># the list that `y` references was unaffected by the update</span>
<span class="go">[0, 1]</span>
</pre></div>
</div>
<p><strong>Understanding References: Solutions</strong></p>
<p>Integers are immutable, thus <code class="docutils literal"><span class="pre">x</span></code> must reference an entirely new object
(<code class="docutils literal"><span class="pre">9</span></code>), and <code class="docutils literal"><span class="pre">y</span></code> still references <code class="docutils literal"><span class="pre">3</span></code>.</p>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="Introduction.html" class="btn btn-neutral float-right" title="Introducing Control Flow" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="SequenceTypes.html" class="btn btn-neutral" title="Sequence Types" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2018, Ryan Soklaski.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'0.9.1',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>