Beginning Python - From Novice to Professional
Beginning Python - From Novice to Professional Beginning Python - From Novice to Professional
CHAPTER 4 ■ DICTIONARIES: WHEN INDICES WON’T DO 79 A Quick Summary In this chapter, you learned about the following: Mappings. A mapping enables you to label its elements with any immutable object, the most usual types being strings and tuples. The only built-in mapping type in Python is the dictionary. String formatting with dictionaries. You can apply the string formatting operation to dictionaries by including names (keys) in the formatting specifiers. When using tuples in string formatting, you need to have one formatting specifier for each element in the tuple. When using dictionaries, you can have fewer specifiers than you have items in the dictionary. Dictionary methods. Dictionaries have quite a few methods, which are called in the same way as list and string methods. New Functions in This Chapter Function dict(seq) Description Creates dictionary from (key, value) pairs What Now? You now know a lot about Python’s basic data types and how to use them to form expressions. As you may remember from Chapter 1, computer programs have another important ingredient—statements. They’re covered in detail in the next chapter.
- Page 60 and 61: CHAPTER 1 ■ INSTANT HACKING: THE
- Page 62 and 63: CHAPTER 2 ■ ■ ■ Lists and Tup
- Page 64 and 65: CHAPTER 2 ■ LISTS AND TUPLES 33 I
- Page 66 and 67: CHAPTER 2 ■ LISTS AND TUPLES 35 A
- Page 68 and 69: CHAPTER 2 ■ LISTS AND TUPLES 37 >
- Page 70 and 71: CHAPTER 2 ■ LISTS AND TUPLES 39 M
- Page 72 and 73: CHAPTER 2 ■ LISTS AND TUPLES 41 T
- Page 74 and 75: CHAPTER 2 ■ LISTS AND TUPLES 43 L
- Page 76 and 77: CHAPTER 2 ■ LISTS AND TUPLES 45 W
- Page 78 and 79: CHAPTER 2 ■ LISTS AND TUPLES 47
- Page 80 and 81: CHAPTER 2 ■ LISTS AND TUPLES 49 a
- Page 82 and 83: CHAPTER 2 ■ LISTS AND TUPLES 51 S
- Page 84 and 85: CHAPTER 3 ■ ■ ■ Working with
- Page 86 and 87: CHAPTER 3 ■ WORKING WITH STRINGS
- Page 88 and 89: CHAPTER 3 ■ WORKING WITH STRINGS
- Page 90 and 91: CHAPTER 3 ■ WORKING WITH STRINGS
- Page 92 and 93: CHAPTER 3 ■ WORKING WITH STRINGS
- Page 94 and 95: CHAPTER 3 ■ WORKING WITH STRINGS
- Page 96 and 97: CHAPTER 3 ■ WORKING WITH STRINGS
- Page 98 and 99: CHAPTER 4 ■ ■ ■ Dictionaries:
- Page 100 and 101: CHAPTER 4 ■ DICTIONARIES: WHEN IN
- Page 102 and 103: CHAPTER 4 ■ DICTIONARIES: WHEN IN
- Page 104 and 105: CHAPTER 4 ■ DICTIONARIES: WHEN IN
- Page 106 and 107: CHAPTER 4 ■ DICTIONARIES: WHEN IN
- Page 108 and 109: CHAPTER 4 ■ DICTIONARIES: WHEN IN
- Page 112 and 113: CHAPTER 5 ■ ■ ■ Conditionals,
- Page 114 and 115: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 116 and 117: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 118 and 119: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 120 and 121: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 122 and 123: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 124 and 125: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 126 and 127: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 128 and 129: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 130 and 131: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 132 and 133: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 134 and 135: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 136 and 137: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 138 and 139: CHAPTER 5 ■ CONDITIONALS, LOOPS,
- Page 140 and 141: CHAPTER 6 ■ ■ ■ Abstraction I
- Page 142 and 143: CHAPTER 6 ■ ABSTRACTION 111 Creat
- Page 144 and 145: CHAPTER 6 ■ ABSTRACTION 113 def t
- Page 146 and 147: CHAPTER 6 ■ ABSTRACTION 115 >>> n
- Page 148 and 149: CHAPTER 6 ■ ABSTRACTION 117 >>> s
- Page 150 and 151: CHAPTER 6 ■ ABSTRACTION 119 WHAT
- Page 152 and 153: CHAPTER 6 ■ ABSTRACTION 121 >>> h
- Page 154 and 155: CHAPTER 6 ■ ABSTRACTION 123 (5, 6
- Page 156 and 157: CHAPTER 6 ■ ABSTRACTION 125 print
- Page 158 and 159: CHAPTER 6 ■ ABSTRACTION 127 So fa
CHAPTER 4 ■ DICTIONARIES: WHEN INDICES WON’T DO 79<br />
A Quick Summary<br />
In this chapter, you learned about the following:<br />
Mappings. A mapping enables you <strong>to</strong> label its elements with any immutable object, the<br />
most usual types being strings and tuples. The only built-in mapping type in <strong>Python</strong> is the<br />
dictionary.<br />
String formatting with dictionaries. You can apply the string formatting operation <strong>to</strong><br />
dictionaries by including names (keys) in the formatting specifiers. When using tuples in<br />
string formatting, you need <strong>to</strong> have one formatting specifier for each element in the tuple.<br />
When using dictionaries, you can have fewer specifiers than you have items in the dictionary.<br />
Dictionary methods. Dictionaries have quite a few methods, which are called in the same<br />
way as list and string methods.<br />
New Functions in This Chapter<br />
Function<br />
dict(seq)<br />
Description<br />
Creates dictionary from (key, value) pairs<br />
What Now?<br />
You now know a lot about <strong>Python</strong>’s basic data types and how <strong>to</strong> use them <strong>to</strong> form expressions.<br />
As you may remember from Chapter 1, computer programs have another important ingredient—statements.<br />
They’re covered in detail in the next chapter.