Written as an illustrated, step-by-step guide, this book will introduce you to Python with examples using the latest version of the language. You'll begin by learning to set up your Python environment. The next few chapters cover the basics of Python such as language classifications, Python language syntax, and how to write a program. Next, you will learn how to work with variables, basic data types, arithmetic, companion, and Boolean operators, followed by lab exercises. Further, the book covers flow control, using functions, and exception handling, as well as the principles of object-oriented programming and building an interface design. The last section explains how to develop a game by installing PyGame and how to use basic animation, and concludes with coverage of Python web development with web servers and Python web frameworks. The Absolute Beginners Guide to Python Programming will give you the tools, confidence, and inspiration to start writing Python programs. If you are a programmer, developer, or a student, or someone who wants to learn on their own, this book is for you. What You Will Learn Gain an understanding of computer programming Understand different data and data types Work with Classes and OOP Build interfaces, simple games, and web development with Python Who This Book Is For Software programmers, developers or students, or anyone who wants to learn Python programming on their own. Table of Contents 4 About the Author 11 About the Technical Reviewer 12 Introduction 13 Chapter 1: Introduction to Computer Programming 14 What Is Python 15 Getting Started 17 Setting Up 17 Install on Windows 17 Install on MacOS 22 Install on Linux 24 Summary 26 Chapter 2: The Basics 27 Language Classification 27 Low-Level Language 27 High-Level Language 28 Python Language Syntax 30 Reserved Words 30 Identifiers 32 Indentation 32 Comments 32 Input 33 Output 33 Escape Characters 33 Writing a Program 34 Lab Exercises 41 Why should you include comments? 41 Chapter 3: Working with Data 43 Variables 43 Local Variables 43 Global Variables 44 Basic Data Types 44 Integers 44 Floating Point Numbers 45 Strings 45 Lists 45 Two-Dimensional Lists 47 Sets 49 Tuples 49 Dictionaries 50 Program Input 51 Program Output 52 Casting Data Types 53 Arithmetic Operators 54 Operator Precedence 54 Performing Arithmetic 55 Comparison Operators 55 Boolean Operators 56 Bitwise Operators 57 Lab Exercises 57 Summary 58 Chapter 4: Flow Control 60 Sequence 60 Selection 63 if... else 63 elif 66 Iteration (Loops) 72 For Loop 72 While Loop 76 Break and Continue 79 Lab Exercises 80 Summary 80 Chapter 5: Handling Files 82 File Types 82 Text File 82 Binary 83 Text File Operations 84 Open Files 84 Write to a File 86 Read from a File 89 Binary File Operations 90 Open Files 90 Write to a File 91 Read a File 92 Random File Access 94 Lab Exercises 95 Summary 96 Chapter 6: Using Functions 97 Declaring Functions 97 Scope 100 Recursion 100 Lab Exercises 102 Summary 103 Chapter 7: Using Modules 104 Importing Modules 105 Creating Your Own Modules 109 Lab Exercises 110 Summary 111 Chapter 8: Exception Handling 112 Types of Exception 112 Catching Exceptions 114 Raising Your Own Exceptions 116 Summary 117 Chapter 9: Object-Oriented Programming 118 Principles of OOP 118 Encapsulation 118 Inheritance 119 Polymorphism 119 Abstraction 119 Classes and Objects 119 Class Inheritance 122 Polymorphic Classes 125 Method Overriding 126 Lab Exercises 128 Summary 129 Chapter 10: Building an Interface 130 Creating a Window 130 Adding Widgets 133 Menus 133 The Canvas 135 Images 138 Buttons 139 Message Boxes 140 Text Field 141 Listbox 142 Checkbox 144 Labels 146 Label Frame 147 Interface Design 148 Summary 153 Chapter 11: Developing a Game 154 Installing Pygame 154 Opening a Window 156 Adding an Image 157 The Game Loop 158 The Event Loop 160 Shapes 164 Basic Animation 165 Summary 173 Chapter 12: Python Web Development 175 Web Servers 175 Install the Web Server 177 Set Up Python Support 177 Executing a Script 179 Python Web Frameworks 183 Summary 189 Appendix A: Quick Reference 190 Data Types 190 Numeric Operators 190 Comparison Operators 191 Boolean Operators 191 String Operators 191 List Operators 191 Dictionary Operators 192 String Methods 192 List Methods 192 Dictionary Methods 192 Functions 193 Files 193 Conditional 193 Multi-conditional 193 While Loop 194 For Loop 194 Loop Control 194 Modules 194 Built-In Functions 194 Declare a Class 195 Child Class 195 Create Object 195 Call Object Method 195 Access Object Attributes 195 Exceptions 195 Index 196 "Written as an illustrated, step-by-step guide, this book will introduce you to Python with examples using the latest version of the language. You'll begin by learning to set up your Python environment. The next few chapters cover the basics of Python such as language classifications, Python language syntax, and how to write a program. Next, you will learn how to work with variables, basic data types, arithmetic, companion, and Boolean operators, followed by lab exercises. Further, the book covers flow control, using functions, and exception handling, as well as the principles of object-oriented programming and building an interface design. The last section explains how to develop a game by installing PyGame and how to use basic animation, and concludes with coverage of Python web development with web servers and Python web frameworks. The Absolute Beginners Guide to Python Programming will give you the tools, confidence, and inspiration to start writing Python programs. If you are a programmer, developer, or a student, or someone who wants to learn on their own, this book is for you."-- Back cover