-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathopen_python.html
More file actions
executable file
·71 lines (68 loc) · 3.96 KB
/
open_python.html
File metadata and controls
executable file
·71 lines (68 loc) · 3.96 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
<!DOCTYPE html>
<html>
<head>
<script src="/bjc-r/llab/loader.js"></script>
<title>Starting Up Python</title>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-176402054-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-176402054-1');
</script>
</head>
<body>
<p class="alert alert-danger quoteRed">
Python can be tricky to run at first on some computers. Always ask if you're having trouble.
</p>
<h3>On Mac OS X: (including in-lab computers)</h3>
<p>
You'll be running python from the Terminal application that we learned about on the last page.
</p>
<h3>On Windows</h3>
<p>
Python may not be set up properly on windows. If you are unable to get python to work from the command line (as explained below) here is a <a href="https://docs.python.org/3.4/faq/windows.html" target="_blank">link</a> that will help you get things set up if you'd like to work on your Windows machine.
</p>
<h3>Running Python</h3>
<p>
The first step is to open the Python <b>interpreter</b>. On the command line in your terminal, use the command <code>python3</code>. If you see something like "command not found", then use the command <code>python</code> instead. You should see something similar to the following:
</p>
<p><pre><code>
Alonzos-MacBook:~ alonzo$$ python3
Python 3.4.0 (v3.4.0:04f714765c13, Month DD YYYY, HH:MM:SS)
[GCC X.X.X] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
</code></pre></p>
<br />
<p class="alert alert-info quoteBlue"><strong>python and python3, what's the difference?</strong> When you open Python with one of these commands, check out the text that appears like above. You'll see something like <code>Python 3.4.0</code> or <code>Python 2.7.10</code>. These are just different versions of Python. The folks who develop Python release updates as new versions, just like apps on the App Store. Don't worry, both versions will work for this lab.</p>
<br />
<p>
We're now using Python! Notice that we still have a <b>prompt</b>, but it looks like this now: <code>>>></code>. The <code>>>></code> indicates that we're using Python right now, and is where we can type Python code. After typing a line of code, hitting <code>enter</code> will tell the python interpreter to run the instruction. Try typing the following into the interpreter:
</p>
<p><pre><code>
>>> 3 + 5
8
</code></pre></p>
<p class="alert alert-danger quoteRed">
If the text cursor is on a line beginning with <code>>>></code>, the command line window has an active python interpreter open. <b>That means we can't do commands like <code>cd</code>, or <code>ls</code>, because the program is expecting Python code.</b> To leave the python interpreter, type the exit command <code>exit()</code> and press <code>enter</code>.
<p><pre><code>
>>> exit()
Alonzos-MacBook:~ alonzo$$
</code></pre></p>
<p>
Any functions or variables created in the python interpreter are erased when the <code>exit()</code> command is run.
</p>
<p>
Here are some basic concepts about the Python <b>intepreter</b> you should understand before you move on:
<ul>
<li>Open the interpreter with the command <code>python</code> or <code>python3</code>.</li>
<li>The interpreter will run the code you typed every time you press <code>enter</code>.</li>
<li>
Exit the interpreter with the command <code>exit()</code>. Now you can use commands like <code>cd</code> and <code>ls</code> again, and whatever you did in Python is lost.
</li>
</ul>
</p>
</body>
</html>