mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
search box and more skip links
This commit is contained in:
@@ -10,6 +10,8 @@ body{counter-reset:h1 1}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p class="skip"><a href="#divingin">skip to main content</a>
|
||||
<form action="http://www.google.com/cse" id="search"><div><input type="hidden" name="cx" value="014021643941856155761:l5eihuescdw"><input type="hidden" name="ie" value="UTF-8"> <input name="q" size="31"> <input type="submit" name="sa" value="Search"></div><p>You are here: <a href="index.html">Dive Into Python 3</a> <span>‣</span> <b>Chapter 2</b></form>
|
||||
<h1>Your first Python program</h1>
|
||||
<blockquote class="q">
|
||||
<p><span>❝</span> Don’t bury your burden in saintly silence. You have a problem? Great. Rejoice, dive in, and investigate. <span>❞</span><br>— <cite>Ven. Henepola Gunararatana</cite>
|
||||
@@ -17,7 +19,7 @@ body{counter-reset:h1 1}
|
||||
<ol>
|
||||
<li><a href="#divingin">Diving in</a>
|
||||
<li><a href="#declaringfunctions">Declaring functions</a>
|
||||
<li><a href="#documentingfunctions">Documenting functions</a>
|
||||
<li><a href="#readability">Writing readable code</a>
|
||||
</ol>
|
||||
<h2 id="divingin">Diving in</h2>
|
||||
<p class="fancy">You know how other books go on and on about programming fundamentals and finally work up to building something useful? Let's skip all that. Here is a complete, working Python program. It probably makes absolutely no sense to you. Don't worry about that, because you're going to dissect it line by line. But read through it first and see what, if anything, you can make of it.
|
||||
@@ -92,7 +94,10 @@ if __name__ == "__main__":
|
||||
<tr><th>Weakly typed</th><td>C, Objective-C</td><td>JavaScript, Perl 5, PHP</td></tr>
|
||||
<tr><th>Strongly typed</th><td>Pascal, Java</td><td>Python, Ruby</td></tr>
|
||||
</table>
|
||||
<h2 id="documentingfunctions">Documenting functions</h2>
|
||||
<h2 id="readability">Writing readable code</h2>
|
||||
|
||||
FIXME
|
||||
|
||||
<p>You can document a Python function by giving it a <code>docstring</code>. In this program, the <code>approximate_size</code> function has a <code>docstring</code>:
|
||||
<pre><code>def approximate_size(size, a_kilobyte_is_1024_bytes=True):
|
||||
"""Convert a file size to human-readable form.
|
||||
|
||||
Reference in New Issue
Block a user