Python Coding – One Year Later: A Treasure Trove of Practical and Simple Examples
- Length: 420 pages
- Edition: 1
- Language: English
- Publication Date: 2020-12-28
- ISBN-10: B08RJ2W1TY
The primary goal of this book is to learn the simple basics of debugging a Python script so your code runs the first (or second) time. Debugging is the process of finding and removing “bugs” or defects in a program. Debugging is also useful in getting your code to run in the first place! Chapter 3 presents “Python Basics” because a big part of debugging is knowing the correct syntax for a particular object and task. This book doesn’t try to cover all the nuances of Python but does cover the terms and syntax you’re likely to encounter in your first few weeks or months of programming. The overhead and clutter are gone, leaving behind clear and simple instructions. Code examples are self-contained so you can copy and paste them into your IDE and run the program. There are certainly more elegant ways to do many of these tasks, but I wanted to demonstrate each concept with a working piece of code limited to a few lines. In Chapter 3 we’ll look at the following topics and more. •Functions, Lists, Dictionaries, Tuples, Ranges, Comprehensions•Indexing, Slicing, Comparison Operators, Control StatementsWhen looking at concepts such as indexing, slicing, scope, or recursive functions, I’ve included lots of diagrams. We’ll look at syntax relevant to each type of object. For example, to add to a “list,” you could use ‘append,’ ‘join’ or ‘extend’ methods. While adding a new key:value pair to a dictionary is straightforward, adding to an existing dictionary is not. In this scenario, it’s not about the value of the object in the key:value pair, but more about the “type” of object in the key:value pair. Once you know the type of the dictionary object, you’ll use the corresponding methods to add or change values, whether it’s a “list,” “string,” “tuple,” or even another dictionary.There are dozens of real-world code examples. Between the detailed Table of Contents and extensive Index, you can quickly find what you’re looking for. The Index includes common phrases for those times when you don’t know the technical term. For example, to find a string in Python you could use the “in”, comparison operator. Whether you look for “find” or “search” the Index refers you to the “in” comparison operator. The examples are varied so you can work with different types of data, such as: xml, html, matplotlib (plots/charts/graphs), OS (files/directories), *.txt, *.csv, user input, or date data.