You are on page 1of 101
Binary Boolean Operators The not Operator Mixing Boolean and Comparison Operators Elements of Flow Contol Conditions Blocks of Code Program Execution Flow Control Stotements if Stalements else Statements elif Statements while Loop Statements break Statements continue Statements. for Loops ond the rangel) Function Importing Modules from impor! Statements Ending @ Program Early with sys Summary Practice Questions 3 FUNCTIONS def Statements with Parameters Return Values and return Statements The None Value Keyword Arguments and print) Local and Global Seope Local Variables Cannot Be Used in the Global Scope Local Seopes Cannot Use Variables in Other Local Scopes Global Variables Con Be Read from o Local Scope. local end Global Variables with the Some Name The globo Statement Exception Handling A Short Program: Guess the Number Summary os + Practice Questions Practice Projects... The Collatz Sequence - Input Validation 4 usts The List Dota Type Getting Individval Volves in List with Indexes Negative Indexes Getting Sublist with Slices Getting a Lis’s Length with lent) Changing Values in o list with Indexes 79 80 80 82 82 83 83 List Concatenation and list Replication Removing Values from Lists with del Statements. Working with Liss Using for Loops with Lists The in and not in Operators The Multiple Assignment Trick Augmented Assignment Operators Methods Finding a Value in List with the indexi) Method ‘Adding Values to Lists wth the oppendi) and insert] Methods Removing Values from lists with removel) Sorting the Valves in a List with the sort) Method Example Program: Magic 8 Ball with a List Listlike Types: Sirings ond Tuples ‘Mutable and Immutable Data Types ‘The Tuple Data Type Converting Types with the lst) and tuple() Functions References. Passing References The copy Module’s copy|) and deepeopy|) Functions. Summary Practice Questions Practice Projects Comma Code’ Character Picture Grid 5 DICTIONARIES AND STRUCTURING DATA ‘The Dictionary Data Type Dictionaries vs. Liss The keys)), values), and items) Methods Checking Whether a Key or Value Exists in a Dictionary The gett) Method. The setdefault) Method Prety Printing Using Dote Structures fo Model Real World Things A TiccToccToe Board. Nested Dictionaries and lists Summary Practice Questions Pracice Projects. . o Fantasy Gome Inventory List to Dictionary Function for Fantasy Game Inventory 6 MANIPULATING STRINGS Working with Stings Sting literals Indexing and Sicing Stings The in and notin Operators with Stings 123 123 124 126 127 Useful String Methods The upper() lower), supper), and islower!) Sting Methods The isk String Methods The startswith)) and endswith) Sting Methods The join() and split) String Methods Jusifying Text with rust, vs, ond center Removing Whitespace with stip0), rtrip0), ond Isip() Copying and Pasting Strings with the pyperclip Module. Project: Password Locker Step 1: Program Design and Data Structures Step 2: Handle Command Line Arguments Step 3: Copy the Right Password Project: Adding Bullets to Wiki Markup. Step 1: Copy and Paste from the Clipboard Step 2: Separate the Lines of Text and Add the Star Step 3: Join the Modified Lines Summary Practice Questions Practice Project Table Printer PART AUTOMATING TASKS 7 PATTERN MATCHING WITH REGULAR EXPRESSIONS Finding Patterns of Text Without Regular Expressions Finding Patterns of Text with Regular Expressions. Creating Regex Objects Matching Regex Objects Review of Regular Expression Matching More Patten Matching with Regular Expressions Grouping with Parentheses Matching Multiple Groups with the Pipe. Optional Matching with the Question Mark Matching Zero or More with the Stor Matching One or More with the Plus Matching Specific Repettions with Curly Brackets Greedy ond Nongreedy Matching ‘The findall) Method Character Classes Making Your Own Character Classes ‘The Caret and Dollar Sign Characters The Wildcard Character Matching Everything with Dot Star. Matching Newlines with the Dot Character Review of Regex Symbols Case-nsensitive Matching 127 128 129 131 131 133, 134 135 136 136 137 137 139 139 140 141 141 142 142 142 145 147 148 150 150 151 152 152 152 153 154 155 155 156 156 157 158 159 159 161 162 162 163

You might also like