Table Of ContentPython Programming
Practical Python Programming For
Beginners and Experts
Jonathan Yates
Text Copyright © Jonathan Yates
All rights reserved. No part of this guide may be reproduced in any form without
permission in writing from the publisher except in the case of brief quotations embodied
in critical articles or reviews.
Legal & Disclaimer
This document is geared towards providing exact and reliable information in regards to the
topic and issues covered. The publication is sold on the idea that the publisher is not
required to render an accounting, officially permitted, or otherwise, qualified services. If
advice is necessary, legal or professional, a practiced individual in the profession should
be ordered.
- From a Declaration of Principles which was accepted and approved equally by a
Committee of the American Bar Association and a Committee of Publishers and
Associations.
In no way is it legal to reproduce, duplicate, or transmit any part of this document by
either electronic means or printed format. Recording of this publication is strictly
prohibited, and any storage of this document is not allowed unless with written permission
from the publisher. All rights reserved.
The information provided herein is stated to be truthful and consistent, in that any liability,
regarding inattention or otherwise, by any usage or abuse of any policies, processes, or
directions contained within is the solitary and utter responsibility of the recipient reader.
Under no circumstances will any legal responsibility or blame be held against the
publisher for any reparation, damages, or monetary loss due to the information herein,
either directly or indirectly.
Respective authors own all copyrights not held by the publisher.
The information herein is offered for informational purposes solely and is universal as so.
The presentation of the information is without a contract or any type of guarantee
assurance.
The trademarks that are used are without any consent, and the publication of the trademark
is without permission or backing by the trademark owner. All trademarks and brands
within this book are for clarifying purposes only and are the owned by the owners
themselves, not affiliated with this document.
Table of Contents
Introduction
Chapter 1: An Introduction to Python
Chapter 2: Installing Python and Setting up the Environment
Chapter 3: Common Python Syntax
Chapter 4: Types of Variables in Python
Chapter 5: Using Operators and Operands
Chapter 6: Using Sequential Loops
Chapter 7: Decision Making and Expressions
Chapter 8: Strings and Functions in Python
Chapter 9: Creating, Using, and Modifying Lists
Chapter 10: Tuples and Data Types
Chapter 11: Dictionary Operation and Functions
Chapter 12: Mastering Date and Time
Chapter 13: User Defined Functions
Chapter 14: Organizing Code with Modules
Chapter 15: I/O Input Used in Python
Chapter 16: Exceptions and Assertions
Chapter 17: Object Oriented Programming
Chapter 18: Python Regular Expressions.
Chapter 19: Python Multithreaded Programming
Chapter 20: Conclusion
Chapter 1
An Introduction to Python
Are you aware that websites like YouTube and Dropbox make use of Python
Programming in their source code? Python is a commonly used language which one can
easily understand and apply. You can make nearly anything using Python. Most systems
today (Mac, Linux, UNIX, etc.) have Python installed as a default setting since it is an
open source and free language. Upon reading this book, you are going to become fluent in
this awesome code language and see it applied to a variety of examples. No type
declaration of methodology, parameters, functions, or variables (like in other languages)
are found in Python making its code concise and easy. As I said earlier, you can use the
language in everything if you want to build a website, make a game, or even create a
search engine. The big plus of using Python is, an explicit compiler is not necessary since
it’s an entirely interpreted language (Perl, Shell, etc.).
File extension which is used by Python source file is “.py” and it is a case-sensitive
language, so “P” and “p” would be considered as two different variables. Also, Python
figures out the variable type on its own, for example, if you put x=4 and y=’Python’ then it
will consider x as an integer and y as a string. We are going to learn all these basics in
detail in further chapters. Before we move forward, a few important points to remember
are:
1. For assigning a value “=” is used, and for comparison “==” is used. Example,
x=4, y=8, x==y
2. “print” is used to print results.
3. All the mathematical operations like +, -, *, /, % are used with numbers
4. Variable is created when a value is assigned to it. Example, a=5 will create a
variable named “a” which has an integer value of 5. There is no need to define it
beforehand.
5. “+” can also be used to concatenate two string. Example, z= “Hi”, z= z +
“Python”
6. For logical operations “and”, “or”, “not” are used instead of symbols.
We use three general data types: integer (by default for numbers), floats (a=3.125) and
string. The string is shown by either “” (double quotes) or ‘’ (single quotes). We will look
at all the types of data with various examples in the upcoming chapters.
Let’s look at the step by step guide to install Python on a Windows operating system. As
mentioned earlier, if you are using another operating system like UNIX or Linux or Mac
then Python should be installed already and ready to use. You have to use “%python” to
get the details on Linux, press “CTRL + D” to exit. For running it on UNIX, “%python
filename.py” is used. Python prompts with three “greater than” symbol (>>>).