Learn Python quick
By Jens Braun
Copyright © 2020
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law.
Preface
This book is written to help you learn Learn Python quick. If you are an absolute beginner in Programming, you'll find that this book explains complex concepts in an easy to understand manner. Examples are carefully chosen to demonstrate each concept so that you can gain a deeper understand of the language. If you are an experienced coder, this book gives you a good base from which to explore Python. The appendices at the end of the book will also provide you with a convenient reference for some of the commonly used functions in Python.
In addition: "The best way of learning about anything is by doing". At the end of the course, you'll be guided through a project that gives you a chance to put what you've learned to use.
Table of Contents
Chapter 1: Python, what Python? Chapter 1: Python, what Python? Welcome to the exciting world of programming. I'm so glad you picked up this book and I sincerely hope this book can help you master the Python language and experience the exhilaration of programming. Before we dive into the nuts and bolts of Python programming, let us first answer a few questions.
What is Python? What is Python? Python is a widely used high-level programming language created by Guido van Rossum in the late 1980s. The language places strong emphasis on code readability and simplicity, making it possible for programmers to develop applications rapidly. Like all high level programming languages, Python code resembles the English language which computers are unable to understand. Codes that we write in Python have to be interpreted by a special program known as the Python interpreter, which we’ll have to install before we can code, test and execute our Python programs. We'll look at how to install the Python interpreter in Chapter 2. There are also a number of third-party tools, such as Py2exe or Pyinstaller that allow us to package our Python code into stand-alone executable programs for some of the most popular operating systems like Windows and Mac OS. This allows us to distribute our Python programs without requiring the users to install the Python interpreter.
Why Learn Python? Why Learn Python? There are a large number of high level programming languages available, such as C, C++, and Java. The good news is all high level programming languages are very similar to one another. What differs is mainly the syntax, the libraries available and the way we access those libraries. A library is simply a collection of resources and pre-written codes that we can use when we write our programs. If you learn one language well, you can easily learn a new language in a fraction of the time it took you to learn the first language. If you are new to programming, Python is a great place to start. One of the key features of Python is its simplicity, making it the ideal language for beginners to learn. Most programs in Python require considerably fewer lines of code to perform the same task compared to other languages such as C. This leads to fewer programming errors and reduces the development time needed. In addition, Python comes with an extensive collection of third party resources that extend the capabilities of the language. As such, Python can be used for a large variety of tasks, such as for desktop applications, database applications, network programming, game programming and even mobile development. Last but not least, Python is a cross platform language, which means that code written for one operating system, such as Windows, will work well on Mac OS or Linux without making any changes to the Python code. Convinced that Python is THE language to learn? Let’s get started...
Chapter 2: Getting ready for Python Chapter 2: Getting ready for Python Installing the Interpreter Before we can write our first Python program, we have to download the appropriate interpreter for our computers. We’ll be using Python 3 in this book because as stated on the official Python site “ Python 2.x is legacy, Python 3.x is the present and future of the language ”. In addition, “ Python 3 eliminates many quirks that can unnecessarily trip up beginning programmers ”. However, note that Python 2 is currently still rather widely used. Python 2 and 3 are about 90% similar. Hence if you learn Python 3, you will likely have no problems understanding codes written in Python 2. To install the interpreter for Python 3, head over to https://www.python.org/downloads/ . The correct version should be indicated at the top of the webpage. Click on the version for Python 3 and the software will start downloading. Alternatively if you want to install a different version, scroll down the page and you’ll see a listing of other versions. Click on the release version that you want. We’ll be using version 3.4.2 in this book. You’ll be redirected to the download page for that version. Scroll down towards the end of the page and you’ll see a table listing various installers for that version. Choose the correct installer for your computer. The installer to use depends on two factors: 1. The operating system (Windows, Mac OS, or Linux) and 2. The processor (32-bit vs 64-bit) that you are using. For instance, if you are using a 64-bit Windows computer, you will likely be using the " Windows x86- 64 MSI installer". Just click on the link to download it. If you download and run the wrong installer, no worries. You will get an error message and the interpreter will not install. Simply download the correct installer and you are good to go. Once you have successfully installed the interpreter, you are ready to start coding in Python.
Installing the Interpreter
Using the Python Shell, IDLE and Writing our FIRST program
Chapter 3: The World of Variables and Operators
What are variables?
Naming a Variable
The Assignment Sign
Basic Operators
More Assignment Operators
Chapter 4: Data Types in Python
Integers
Float
String
Type Casting In Python
List
Tuple
Dictionary
Chapter 5: Making Your Program Interactive
Input()
Print()
Triple Quotes
Escape Characters
Chapter 6: Making Choices and Decisions
Condition Statements
If Statement
Inline If
For Loop
While Loop
Break
Continue
Try, Except
Chapter 7: Functions and Modules
What are Functions?
Defining Your Own Functions
Variable Scope
Importing Modules
Creating our Own Module
Chapter 8: Working with Files
Opening and Reading Text Files
Using a For Loop to Read Text Files
Writing to a Text File
Opening and Reading Text Files by Buffer Size
Opening, Reading and Writing Binary Files
Deleting and Renaming Files
Project: Math and BODMAS
Part 1: myPythonFunctions.py
Part 2: mathGame.py
Challenge Yourself
Thank You
Appendix A: Working With Strings
Appendix B: Working With Lists
Appendix C: Working With Tuples
Appendix D: Working With Dictionaries
Appendix E: Project Answers
One Last Thing…
Chapter 1: Python, what Python?
Welcome to the exciting world of programming. I'm so glad you picked up this book and I sincerely hope this book can help you master the Python language and experience the exhilaration of programming. Before we dive into the nuts and bolts of Python programming, let us first answer a few questions.
Читать дальше