-->
Navigation
Python All-In-One for Dummies

Python All-In-One for Dummies

Now pay Easier and Secure using Paypal
Price:

Read more

by John Shovic and Alan Simpson

7 BOOKS IN ONE

Contents at a Glance

Book 1: Getting Started with Python
Starting with Python
Interactive Mode, Getting Help, Writing Apps
Python Elements and Syntax
Building Your First Python Application
Book 2: Understanding Python Building Blocks
Working with Numbers, Text, and Dates
Controlling the Action
Speeding Along with Lists and Tuples
Cruising Massive Data with Dictionaries
Wrangling Bigger Chunks of Code
Doing Python with Class
Sidestepping Errors
Book 3: Working with Python Libraries
Working with External Files
Juggling JSON Data
Interacting with the Internet
Libraries, Packages, and Modules
Book 4: Using Artificial Intelligence in Python
Exploring Artificial Intelligence
Building a Neural Network in Python
Doing Machine Learning in Python
Exploring More AI in Python
Book 5: Doing Data Science with Python
The Five Areas of Data Science
Exploring Big Data with Python
Using Big Data from the Google Cloud
Book 6: Talking to Hardware with Python
Introduction to Physical Computing
No Soldering! Grove Connectors for Building Things
Sensing the World with Python: The World of I2C
Making Things Move with Python
Book 7: Building Robots with Python
Introduction to Robotics
Building Your First Python Robot
Programming Your Robot Rover in Python
Using Artificial Intelligence in Robotics.

e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 6.00
 Pages
 703 p
 File Size 
 41,873 KB
 File Type
 PDF format
 ISBN
 978-1-119-55759-3 (pbk)
 978-1-119-55767-8 (ebk)
 978-1-119-55761-6 (ebk)
 Copyright©   
 2019 by John Wiley & Sons, Inc 

Introduction
The power of Python. The Python language is becoming more and more popular,
and in 2017 it became the most popular language in the world according
to IEEE Spectrum. The power of Python is real.

Why is Python the number one language? Because it is incredibly easy to learn
and use. Part of it is its simplified syntax and its natural-language flow, but a lot
of it has to do with the amazing user community and the breadth of applications available.

About This Book
This book is a reference manual to guide you through the process of learning
Python and how to use it in modern computer applications, such as data science,
artificial intelligence, physical computing, and robotics. If you are looking to learn
a little about a lot of exciting things, then this is the book for you. It gives you an
introduction to the topics that you will need to go deeper into any of these areas of technology.

This book guides you through the Python language and then it takes you on a tour
through some really cool libraries and technologies (the Raspberry Pi, robotics, AI,
data science, and so on) all revolving around the Python language. When you work
on new projects and new technologies, Python is there for you with an incredibly
diverse number of libraries just waiting for you to use.

This is a hands-on book. There are examples and code all throughout the book.
You are expected to take the code, run it, and then modify it to do what you want.
You don’t just buy a robot, you build it so you can understand all the pieces and
can make sense of the way Python works with the robot to control all the motors
and sensors. Artificial intelligence is complicated, but Python helps make a significant
part of it accessible. Data science is complicated, but Python helps you do
data science more easily. Robotics is complicated, but Python gives you the code
that controls the robot. And Python even allows us to tie these pieces together and
use, say, AI in robotics.

In this book, we take you through the basics of the Python language in small,
easy-to-understand steps. After we have introduced you to the language, then we
step into the world of Python and artificial intelligence, exploring programming
in machine learning and neural networks using Python and TensorFlow and actually
working on real problems and real software, not just toy applications.
After that, we’re off to the exciting world of Big Data and data science with Python.
We look at big public data sets such as medical and environmental data all using Python.

Finally, you get to experience the magic of what I call “physical computing.”
Using the small, inexpensive Raspberry Pi computer (it’s small, but incredibly
popular) we show you how to use Python to control motors and read sensors. This
is a lead-up to our final book, “Python and Robotics.” Here you learn how to build
a robot and how to control that robot with Python and your own programs, even
using artificial intelligence.
This is not your mother’s RC car.
Python data science, robotics, AI, and fun all in the same book.
This book won’t make you understand everything about these fields, but it will
give you a great introduction to the terminology and the power of Python in all
these fields. Enjoy the book and go forth and learn more afterwards.

Table of Contents
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 of AI . 363
CHAPTER 2: Building a Neural Network in Python. 365
Understanding Neural Networks . 366
Layers of neurons. 367
Weights and biases. 368
The activation function. 369
Loss function . 369
Building a Simple Neural Network in Python . 370
The neural-net Python code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .370
Using TensorFlow for the same neural network. 381
Installing the TensorFlow Python library. 382
Building a Python Neural Network in TensorFlow. 383
Loading your data. 384
Defining your neural-network model and layers. 384
Compiling your model . 384
Fitting and training your model. 384
Breaking down the code. 386
Evaluating the model . 388
Changing to a three-layer neural network in
TensorFlow/Keras. 390
CHAPTER 3: Doing Machine Learning in Python. 393
Learning by Looking for Solutions in All the Wrong Places. 394
Classifying Clothes with Machine Learning. 395
Training and Learning with TensorFlow. 395
Setting Up the Software Environment for this Chapter. 396
Creating a Machine-Learning Network for Detecting
Clothes Types. 397
Getting the data — The Fashion-MNIST dataset. 398
Training the network. 398
Testing our network . 398
Breaking down the code. 399
Results of the training and evaluation. 402
Testing a single test image. 402
Testing on external pictures . 403
The results, round 1 . 405
The CNN model code . 406
The results, round 2 . 409
Visualizing with MatPlotLib . 409
Learning More Machine Learning. 413
CHAPTER 4: Exploring More AI in Python. 415
Limitations of the Raspberry Pi and AI. 415
Adding Hardware AI to the Raspberry Pi. 418
AI in the Cloud. 420
Google cloud . 421
Amazon Web Services. 421
IBM cloud. 422
Microsoft Azure. 422
AI on a Graphics Card. 423
Where to Go for More AI Fun in Python. 424
BOOK 5: DOING DATA SCIENCE WITH PYTHON. 427
CHAPTER 1: The Five Areas of Data Science. 429
Working with Big, Big Data. 430
Volume. 430
Variety. 431
Velocity. 431
Managing volume, variety, and velocity. 432
Cooking with Gas: The Five Step Process of Data Science. 432
Capturing the data . 433
Processing the data. 433
Analyzing the data. 434
Communicating the results. 434
Maintaining the data. 435
CHAPTER 2: Exploring Big Data with Python. 437
Introducing NumPy, Pandas, and MatPlotLib. 438
Doing Your First Data Science Project . 440
Diamonds are a data scientist’s best friend . 440
Breaking down the code. 443
Visualizing the data with MatPlotLib. 444
CHAPTER 3: Using Big Data from the Google Cloud. 451
What Is Big Data?. 451
Understanding the Google Cloud and BigQuery . 452
The Google Cloud Platform. 452
BigQuery from Google . 452
Computer security on the cloud. 453
Signing up on Google for BigQuery . 454
Reading the Medicare Big Data. 454
Setting up your project and authentication. 454
The first big-data code . 457
Breaking down the code. 460
A bit of analysis next. 461
Payment percent by state . 464
And now some visualization . 465
Looking for the Most Polluted City in the World on
an Hourly Basis . 466
BOOK 6: TALKING TO HARDWARE WITH PYTHON. 469
CHAPTER 1: Introduction to Physical Computing. 471
Physical Computing Is Fun. 472
What Is a Raspberry Pi? . 472
Making Your Computer Do Things. 474
Using Small Computers to Build Projects That Do
and Sense Things. 474
The Raspberry Pi: A Perfect Platform for Physical
Computing in Python . 476
GPIO pins . 477
GPIO libraries. 477
The hardware for “Hello World” . 478
Assembling the hardware . 478
Controlling the LED with Python on the Raspberry Pi. 482
But Wait, There Is More . . . . 485
CHAPTER 2: No Soldering! Grove Connectors
for Building Things . 487
So What Is a Grove Connector?. 488
Selecting Grove Base Units . 489
For the Arduino. 489
Raspberry Pi Base Unit — the Pi2Grover. 490
The Four Types of Grove Connectors. 492
The Four Types of Grove Signals. 493
Grove digital — All about those 1’s and 0’s. 493
Grove analog: When 1’s and 0’s aren’t enough. 494
Grove UART (or serial) — Bit by bit transmission. 495
Grove I2C — Using I2C to make sense of the world. 497
Using Grove Cables to Get Connected. 499
Grove Patch Cables. 499
CHAPTER 3: Sensing the World with Python:
The World of I2C . 505
Understanding I2C . 506
Exploring I2C on the Raspberry Pi. 507
Talking to I2C devices with Python. 508
Reading temperature and humidity from an I2C
device using Python . 511
Breaking down the program. 514
A Fun Experiment for Measuring Oxygen and a Flame. 517
Analog-to-digital converters (ADC). 518
The Grove oxygen sensor. 519
Hooking up the oxygen experiment. 520
Breaking down the code. 522
Building a Dashboard on Your Phone Using Blynk and Python. 525
HDC1080 temperature and humidity sensor redux. 525
How to add the Blynk dashboard. 527
The modified temperatureTest.py software for the
Blynk app . 531
Breaking down the code. 533
Where to Go from Here . 536
CHAPTER 4: Making Things Move with Python. 537
Exploring Electric Motors. 538
Small DC motors . 538
Servo motors. 539
Stepper motors. 539
Controlling Motors with a Computer. 540
Python and DC Motors. 540
Python and running a servo motor. 548
Python and making a stepper motor step. 554
BOOK 7: BUILDING ROBOTS WITH PYTHON. 565
CHAPTER 1: Introduction to Robotics. 567
A Robot Is Not Always like a Human. 567
Not Every Robot Has Arms or Wheels . 568
The Wilkinson Bread-Making Robot. 569
Baxter the Coffee-Making Robot. 570
The Griffin Bluetooth-enabled toaster. 571
Understanding the Main Parts of a Robot. 572
Computers. 572
Motors and actuators. 573
Communications. 573
Sensors. 573
Programming Robots. 574
CHAPTER 2: Building Your First Python Robot. 575
Introducing the Mars Rover PiCar-B. 575
What you need for the build . 576
Understanding the robot components . 577
Assembling the Robot. 586
Calibrating your servos. 588
Running tests on your rover in Python. . . . . . . . . . . . . . . . . . . . . . .591
Installing software for the CarPi-B Python test. 591
The PiCar-B Python test code . 592
Pi camera video testing . 592
CHAPTER 3: Programming Your Robot Rover in Python. 595
Building a Simple High-Level Python Interface. 595
The motorForward function. 596
The wheelsLeft function. 596
The wheelsPercent function . 596
Making a Single Move with Python. 597
Functions of the RobotInterface Class. 598
Front LED functions. 598
Pixel strip functions. 600
Ultrasonic distance sensor function. 601
Main motor functions. 602
Servo functions . 603
General servo function. 606
The Python Robot Interface Test. 606
Coordinating Motor Movements with Sensors. 610
Making a Python Brain for Our Robot . 613
A Better Robot Brain Architecture. . . . . . . . . . . . . . . . . . . . . . . . . . .620
Overview of the Included Adeept Software. 621
Where to Go from Here? . 622
CHAPTER 4: Using Artificial Intelligence in Robotics. . . . . . . . . . . . .623
This Chapter’s Project: Going to the Dogs. 624
Setting Up the Project. 624
Machine Learning Using TensorFlow. 625
The code. 627
Examining the code. 629
The results . 632
Testing the Trained Network. 633
The code. 634
Explaining the code. 636
The results . 637
Taking Cats and Dogs to Our Robot. 640
The code. 640
How it works. 643
The results . 643
Other Things You Can Do with AI Techniques and the Robot . 645
Cat/Not Cat. 645
Santa/Not Santa. 646
Follow the ball . 646
Using Alexa to control your robot. 646
AI and the Future of Robotics . 646
INDEX . 647




Bookscreen
e-books shop

Foolish Assumptions
We assume you know how to use a computer in a very basic way. If you can turn on
the computer and use a mouse, you’re ready for this book. We assume you don’t
know how to program yet, although you will have some skills in programming
by the end of the book. If we’re wrong and you do already know Python (or some
other computer language), jump ahead to minibook 4 and dig right into learning
something new. Our intent is to guide you through the language of Python and
then through some of the amazing technologies and devices that use Python. We
provide complete examples. If you get stuck on something, look it up on the web,
read a tutorial, and then come back to it.

0