Introduction 1 About This Book 1 Foolish Assumptions 2 Icons Used in This Book 2 Beyond the Book 3 Where to Go from Here 3 Book 1: Getting Started with Python 5 Chapter 1: Starting with Python 7 Why Python is Hot 8 Choosing the Right Python 9 Tools for Success 11 An excellent, free learning environment 12 Installing Anaconda and VS Code 13 Writing Python in VS Code 17 Choosing your Python interpreter 19 Writing some Python code 20 Getting back to VS Code Python 21 Using Jupyter Notebook for Coding 21 Chapter 2: Interactive Mode, Getting Help, Writing Apps 27 Using Python Interactive Mode 27 Opening Terminal 28 Getting your Python version 28 Going into the Python Interpreter 30 Entering commands 30 Using Python''s built-in help 31 Exiting interactive help 33 Searching for specific help topics online 33 Lots of free cheat sheets 34 Creating a Python Development Workspace 34 Creating a Folder for your Python Code 37 Typing, Editing, and Debugging Python Code 39 Writing Python code 40 Saving your code 41 Running Python in VS Code 41 Simple debugging 42 The VS Code Python debugger 43 Writing Code in a Jupyter Notebook 45 Creating a folder for Jupyter Notebook 45 Creating and saving a Jupyter notebook 46 Typing and running code in a notebook 46 Adding some Markdown text 47 Saving and opening notebooks 48 Chapter 3: Python Elements and Syntax 49 The Zen of Python 49 Object-Oriented Programming 53 Indentations Count, Big Time 54 Using Python Modules 56 Syntax for importing modules 58 Using an alias with modules 59 Chapter 4: Building Your First Python Application 61 Open the Python App File 62 Typing and Using Python Comments 63 Understanding Python Data Types 64 Numbers 65 Words (strings) 66 True/false Booleans 68 Doing Work with Python Operators 69 Arithmetic operators 69 Comparison operators 70 Boolean operators 71 Creating and Using Variables 72 Creating valid variable names 73 Creating variables in code 74 Manipulating variables 75 Saving your work 76 Running your Python app in VS Code 76 What Syntax is and Why It Matters 78 Putting Code Together 82 Book 2: Understanding Python Building Blocks 83 Chapter 1: Working with Numbers, Text, and Dates 85 Calculating Numbers with Functions 86 Still More Math Functions 88 Formatting Numbers 91 Formatting with f-strings 91 Showing dollar amounts 92 Formatting percent numbers 93 Making multiline format strings 95 Formatting width and alignment 96 Grappling with Weirder Numbers 98 Binary, octal, and hexadecimal numbers 98 Complex numbers 99 Manipulating Strings 100 Concatenating strings 101 Getting the length of a string 102 Working with common string operators 102 Manipulating strings with methods 105 Uncovering Dates and Times 107 Working with dates 108 Working with times 112 Calculating timespans 114 Accounting for Time Zones 118 Working with Time Zones 120 Chapter 2: Controlling the Action 125 Main Operators for Controlling the Action 125 Making Decisions with if 126 Adding else to your if login 130 Handling multiple else''s with elif 131 Ternary operations 133 Repeating a Process with for 134 Looping through numbers in a range 134 Looping through a string 136 Looping through a list 137 Bailing out of a loop 138 Looping with continue 140 Nesting loops 140 Looping with while 141 Starting while loops over with continue 143 Breaking while loops with break 144 Chapter 3: Speeding Along with Lists and Tuples 147 Defining and Using Lists 147 Referencing list items by position 148 Looping through a list 150 Seeing whether a list contains an item 150 Getting the length of a list 151 Adding an item to the end of a list 151 Inserting an item into a list 152 Changing an item in a list 153 Combining lists 153 Removing list items 154 Clearing out a list 156 Counting how many times an item appears in a list 157 Finding an list item''s index 158 Alphabetizing and sorting lists 159 Reversing a list 161 Copying a list 162 What''s a Tuple and Who Cares? 163 Working with Sets 165 Chapter 4: Cruising Massive Data with Dictionaries 169 Creating a Data Dictionary 171 Accessing dictionary data 172 Getting the length of a dictionary 174 Seeing whether a key exists in a dictionary 175 Getting dictionary data with get() 176 Changing the value of a key 177 Adding or changing dictionary data 177 Looping through a Dictionary 179 Data Dictionary Methods 181 Copying a Dictionary 182 Deleting Dictionary Items 182 Using pop() with Data Dictionaries 184 Fun with Multi-Key Dictionaries 186 Using the mysterious fromkeys and setdefault methods 188 Nesting Dictionaries 190 Chapter 5: Wrangling Bigger Chunks of Code 193 Creating a Function 194 Commenting a Function 195 Passing Information to a Function 196 Defining optional parameters with defaults 198 Passing multiple values to a function 199 Using keyword arguments (kwargs) 200 Passing multiple values in a list 202 Passing in an arbitrary number of arguments 204 Returning Values from Functions 205 Unmasking Anonymous Functions 206 Chapter 6: Doing Python with Class 213 Mastering Classes and Objects 213 Creating a Class 216 How a Class Creates an Instance 217 Giving an Object Its Attributes 218 Creating an instance from a class 219 Changing the value of an attribute 222 Defining attributes with default values 222 Giving a Class Methods 224 Passing parameters to methods 226 Calling a class method by class name 227 Using class variables 228 Using class methods 230 Using static methods 232 Understanding Class Inheritance 234 Creating the base (main) class 236 Defining a subclass 237 Overriding a default value from a subclass 239 Adding extra parameters from a subclass 239 Calling a base class method 242 Using the same name twice 243 Chapter 7: Sidestepping Errors 247 Understanding Exceptions 247 Handling Errors Gracefully 251 Being Specific about Exceptions 252 Keeping Your App from Crashing 253 Adding an else to the Mix 255 Using try . except else finally 257 Raising Your Own Errors 259 Book 3: Working with Python Libraries 265 Chapter 1: Working with External Files 267 Understanding Text and Binary Files 267 Opening and Closing Files 269 Reading a File''s Contents 276 Looping through a File 277 Looping with readlines() 277 Looping with readline() 279 Appending versus overwriting files 280 Using tell() to determine the pointer location 281 Moving the pointer with seek() 283 Reading and Copying a Binary File 283 Conquering CSV Files 286 Opening a CSV file 288 Converting strings 290 Converting to integers 291 Converting to date 292 Converting to Boolean 293 Converting to floats 293 From CSV to Objects and Dictionaries 295 Importing CSV to Python objects 296 Importing CSV to Python dictionaries 299 Chapter 2: Juggling JSON Data 303 Organizing JSON Data 303 Understanding Serialization 306 Loading Data from JSON Files 307 Converting an Excel date to a JSON date 309 Looping through a keyed JSON file 310 Converting firebase timestamps to Python dates 313 Loading unkeyed JSON from a Python string 314 Loading keyed JSON from a Python string 315 Changing JSON data 316 Removing data from a dictionary 317 Dumping Python Data to JSON 318 Chapter 3: Interacting with the Internet 323 How the Web Works 323 Understanding the mysterious URL 324 Exposing the HTTP headers 325 Opening a URL from Python 327 Posting to the Web with Python 328 Scraping the Web with Python 330 Parsing part of a page 333 Storing the parsed content 333 Saving scraped data to a JSON file 335 Saving scraped data to a CSV file 336 Chapter 4: Libraries, Packages, and Modules 339 Understanding the Python Standard Library 339 Using the dir() function 340 Using the help() function 341 Exploring built-in functions 343 Exploring Python Packages 343 Importing Python Modules 345 Making Your Own Modules 348 Book 4: Using Artificial Intelligence in Python 353 Chapter 1: Exploring Artificial Intelligence 355 AI is a Collection of Techniques 356 Neural networks 356 Machine learning 359 TensorFlow -- A framework for deep learning 361 Current Limitations o.
Python All-In-One for Dummies