forked from joshgachnang/diveintopython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.html
More file actions
118 lines (114 loc) · 8.89 KB
/
Copy pathshell.html
File metadata and controls
118 lines (114 loc) · 8.89 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
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>1.8. The Interactive Shell</title>
<link rel="stylesheet" href="/css/diveintopython.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.52.2" />
<meta name="keywords" content="Python, Dive Into Python, tutorial, object-oriented, programming, documentation, book, free" />
<meta name="description" content="Python from novice to pro" />
<link rel="home" href="http://www.diveintopython.net/" title="Dive Into Python" />
<link rel="up" href="http://www.diveintopython.net/" title="Chapter 1. Installing Python" />
<link rel="previous" href="http://www.diveintopython.net/" title="1.7. Python Installation from Source" />
<link rel="next" href="http://www.diveintopython.net/" title="1.9. Summary" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9740779-18']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></head>
<body>
<style type="text/css">body{margin-top:0!important;padding-top:0!important;min-width:800px!important;}#wm-ipp a:hover{text-decoration:underline!important;}</style>
<table id="Header" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
<tr>
<td id="breadcrumb" colspan="5" align="left" valign="top">You are here: <a href="http://www.diveintopython.net/index.html">Home</a> > <a href="http://www.diveintopython.net/toc/index.html">Dive Into Python</a> > <a href="http://www.diveintopython.net/installing_python/index.html">Installing Python</a> > <span class="thispage">The Interactive Shell</span></td>
<td id="navigation" align="right" valign="top"> <a href="http://www.diveintopython.net/installing_python/source.html" title="Prev: “Python Installation from Source”"><<</a> <a href="http://www.diveintopython.net/installing_python/summary.html" title="Next: “Summary”">>></a></td>
</tr>
<tr>
<td colspan="3" id="logocontainer">
<h1 id="logo"><a href="http://www.diveintopython.net/index.html" accesskey="1">Dive Into Python</a></h1>
<p id="tagline">Python from novice to pro</p>
</td>
<td colspan="3" align="right">
<form id="search" method="GET" action="http://www.google.com/custom">
<p><label for="q" accesskey="4">Find: </label><input type="text" id="q" name="q" size="20" maxlength="255" value=" " /> <input type="submit" value="Search" /><input type="hidden" name="cof" value="LW:752;L:http://diveintopython.org/images/diveintopython.png;LH:42;AH:left;GL:0;AWFID:3ced2bb1f7f1b212;" /><input type="hidden" name="domains" value="diveintopython.org" /><input type="hidden" name="sitesearch" value="diveintopython.org" /></p>
</form>
</td>
</tr>
</table>
<div class="section" lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a name="install.shell"></a>1.8. The Interactive Shell
</h2>
</div>
</div>
<div></div>
</div>
<div class="abstract">
<p>Now that you have <span class="application">Python</span> installed, what's this interactive shell thing you're running?
</p>
</div>
<p>It's like this: <span class="application">Python</span> leads a double life. It's an interpreter for scripts that you can run from the command line or run like applications, by
double-clicking the scripts. But it's also an interactive shell that can evaluate arbitrary statements and expressions.
This is extremely useful for debugging, quick hacking, and testing. I even know some people who use the <span class="application">Python</span> interactive shell in lieu of a calculator!
</p>
<p>Launch the <span class="application">Python</span> interactive shell in whatever way works on your platform, and let's dive in with the steps shown here:
</p>
<div class="example"><a name="d0e3829"></a><h3 class="title">Example 1.5. First Steps in the Interactive Shell</h3><pre class="screen">
<tt class="prompt">>>> </tt><span class="userinput">1 + 1</span> <a name="install.shell.1.1"></a><img src="http://www.diveintopython.net/images/callouts/1.png" alt="1" border="0" width="12" height="12" />
<span class="computeroutput">2</span>
<tt class="prompt">>>> </tt><span class="userinput"><span class="pykeyword">print</span> <span class="pystring">'hello world'</span></span> <a name="install.shell.1.2"></a><img src="http://www.diveintopython.net/images/callouts/2.png" alt="2" border="0" width="12" height="12" />
<span class="computeroutput">hello world</span>
<tt class="prompt">>>> </tt><span class="userinput">x = 1</span> <a name="install.shell.1.3"></a><img src="http://www.diveintopython.net/images/callouts/3.png" alt="3" border="0" width="12" height="12" />
<tt class="prompt">>>> </tt><span class="userinput">y = 2</span>
<tt class="prompt">>>> </tt><span class="userinput">x + y</span>
<span class="computeroutput">3</span>
</pre><div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td width="12" valign="top" align="left"><a href="http://www.diveintopython.net/installing_python/shell.html#install.shell.1.1"><img src="http://www.diveintopython.net/images/callouts/1.png" alt="1" border="0" width="12" height="12" /></a>
</td>
<td valign="top" align="left">The <span class="application">Python</span> interactive shell can evaluate arbitrary <span class="application">Python</span> expressions, including any basic arithmetic expression.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="http://www.diveintopython.net/installing_python/shell.html#install.shell.1.2"><img src="http://www.diveintopython.net/images/callouts/2.png" alt="2" border="0" width="12" height="12" /></a>
</td>
<td valign="top" align="left">The interactive shell can execute arbitrary <span class="application">Python</span> statements, including the <span><b class="command">print</b></span> statement.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="http://www.diveintopython.net/installing_python/shell.html#install.shell.1.3"><img src="http://www.diveintopython.net/images/callouts/3.png" alt="3" border="0" width="12" height="12" /></a>
</td>
<td valign="top" align="left">You can also assign values to variables, and the values will be remembered as long as the shell is open (but not any longer
than that).
</td>
</tr>
</table>
</div>
</div>
</div>
<table class="Footer" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
<tr>
<td width="35%" align="left"><br /><a class="NavigationArrow" href="http://www.diveintopython.net/installing_python/source.html"><< Python Installation from Source</a></td>
<td width="30%" align="center"><br /> <span class="divider">|</span> <a href="http://www.diveintopython.net/installing_python/index.html#install.choosing" title="1.1. Which Python is right for you?">1</a> <span class="divider">|</span> <a href="http://www.diveintopython.net/installing_python/windows.html" title="1.2. Python on Windows">2</a> <span class="divider">|</span> <a href="http://www.diveintopython.net/installing_python/macosx.html" title="1.3. Python on Mac OS X">3</a> <span class="divider">|</span> <a href="http://www.diveintopython.net/installing_python/macos9.html" title="1.4. Python on Mac OS 9">4</a> <span class="divider">|</span> <a href="http://www.diveintopython.net/installing_python/redhat.html" title="1.5. Python on RedHat Linux">5</a> <span class="divider">|</span> <a href="http://www.diveintopython.net/installing_python/debian.html" title="1.6. Python on Debian GNU/Linux">6</a> <span class="divider">|</span> <a href="http://www.diveintopython.net/installing_python/source.html" title="1.7. Python Installation from Source">7</a> <span class="divider">|</span> <span class="thispage">8</span> <span class="divider">|</span> <a href="http://www.diveintopython.net/installing_python/summary.html" title="1.9. Summary">9</a> <span class="divider">|</span>
</td>
<td width="35%" align="right"><br /><a class="NavigationArrow" href="http://www.diveintopython.net/installing_python/summary.html">Summary >></a></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
</table>
<div class="Footer">
<p class="copyright">Copyright © 2000, 2001, 2002, 2003, 2004 <a href="mailto:[email protected]">Mark Pilgrim</a></p>
</div>
</body>
</html>