mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
fixed FIXMEs
This commit is contained in:
@@ -31,7 +31,7 @@ body{counter-reset:h1 2}
|
||||
<li><b>Sets</b> are unordered bags of values.
|
||||
<li><b>Dictionaries</b> are unordered bags of key-value pairs.
|
||||
</ol>
|
||||
<p>Of course, there are a lot more types than these seven. <a href=your-first-python-program.html#everythingisanobject>Everything is an object</a> in Python, so there are types like <i>module</i>, <i>function</i>, <i>class</i>, <i>method</i>, <i>file</i>, and even <i>compiled code</i>. You’ve already seen some of these: <a href=your-first-python-program.html#runningscripts>modules have names</a>, <a href=your-first-python-program.html#docstrings>functions have <code>docstrings</code></a>, <i class=baa>&</i>c. You’ll learn about classes in <a href=iterators.html>Classes <i class=baa>&</i> Iterators</a>, and about files in [FIXME xref].
|
||||
<p>Of course, there are a lot more types than these seven. <a href=your-first-python-program.html#everythingisanobject>Everything is an object</a> in Python, so there are types like <i>module</i>, <i>function</i>, <i>class</i>, <i>method</i>, <i>file</i>, and even <i>compiled code</i>. You’ve already seen some of these: <a href=your-first-python-program.html#runningscripts>modules have names</a>, <a href=your-first-python-program.html#docstrings>functions have <code>docstrings</code></a>, <i class=baa>&</i>c. You’ll learn about classes in <a href=iterators.html>Classes <i class=baa>&</i> Iterators</a>, and about files in <a href=files.html>Files</a>.
|
||||
<p>Strings and bytes are important enough — and complicated enough — that they get their own chapter. Let’s look at the others first.
|
||||
<p class=a>⁂
|
||||
|
||||
@@ -695,7 +695,7 @@ KeyError: 'pop from an empty set'</samp></pre>
|
||||
<p><span class=u>☞</span>A dictionary in Python is like a hash in Perl 5. In Perl 5, variables that store hashes always start with a <code>%</code> character. In Python, variables can be named anything, and Python keeps track of the datatype internally.
|
||||
</blockquote>
|
||||
<h3 id=creating-dictionaries>Creating A Dictionary</h3>
|
||||
<p>Creating a dictionary is easy. The syntax is similar to <a href=#sets>sets</a> [FIXME link fails because section is not written yet], but instead of values, you have key-value pairs. Once you have a dictionary, you can look up values by their key.
|
||||
<p>Creating a dictionary is easy. The syntax is similar to <a href=#sets>sets</a>, but instead of values, you have key-value pairs. Once you have a dictionary, you can look up values by their key.
|
||||
<pre class=screen>
|
||||
<a><samp class=p>>>> </samp><kbd class=pp>a_dict = {'server': 'db.diveintopython3.org', 'database': 'mysql'}</kbd> <span class=u>①</span></a>
|
||||
<samp class=p>>>> </samp><kbd class=pp>a_dict</kbd>
|
||||
@@ -758,7 +758,7 @@ KeyError: 'db.diveintopython3.org'</samp></pre>
|
||||
<a><samp class=p>>>> </samp><kbd class=pp>SUFFIXES[1000][3]</kbd> <span class=u>⑤</span></a>
|
||||
<samp class=pp>'TB'</samp></pre>
|
||||
<ol>
|
||||
<li>Like <a href=#lists>lists</a> and <a href=#sets>sets</a> [FIXME-xref], the <code>len()</code> function gives you the number of keys in a dictionary.
|
||||
<li>Like <a href=#lists>lists</a> and <a href=#sets>sets</a>, the <code>len()</code> function gives you the number of keys in a dictionary.
|
||||
<li>And like lists and sets, you can use the <code>in</code> operator to test whether a specific key is defined in a dictionary.
|
||||
<li><code>1000</code> <em>is</em> a key in the <code>SUFFIXES</code> dictionary; its value is a list of eight items (eight strings, to be precise).
|
||||
<li>Similarly, <code>1024</code> is a key in the <code>SUFFIXES</code> dictionary; its value is also a list of eight items.
|
||||
|
||||
Reference in New Issue
Block a user