Understanding Python: Beginner's Guide to Programming
By Sabry Fattah
()
About this ebook
Python is one of the most powerful, easy-to-read programming languages around. This general purpose, high-level language can be extended and embedded in many programming problems. This book will introduce you to programming in Python, going through the skills you need to know for building programs and the way to develop simple code that perform the actions you plan. The book introduces the main concepts in Python language with clear examples to help you master basic elements and syntax; to design programs; work with strings; use control structures; import modules; build lists; create an organized dictionary; handle functions, manage data, and namespace; work with modules and packages; and understand classes.
It is a great resource to maximize your productivity. You will get familiar with Python's building blocks, strings, dictionaries, and sets; and be on your way to writing programs and develop your coding skills.
Sabry Fattah
Dr. Sabry Fattah is a distinguished Consultant Psychiatrist currently residing in the U.K., having relocated there in 1990 after completing his medical education in Cairo, Egypt. He further honed his skills through extensive training in psychodynamic psychotherapy and group therapy. In England, he pursued advanced studies in psychiatry, obtaining an M.Sc. in Neuroscience from the University of London and becoming a Member of the Royal College of Psychiatrists in London. In 1995, Dr. Fattah served as a Research Fellow within the Department of Psychiatry at Edinburgh University, publishing several scholarly articles during his tenure. He practiced as a Consultant Psychiatrist in the U.K. since then. Beyond traditional psychiatric practice, Dr. Fattah boasts a wide range of interests spanning computer programming, scientific writing, philosophy, art, literature, and history. These varied passions have led to numerous publications across disciplines such as psychology, psychiatry, philosophy, computer programming, and linguistics. Over the course of four decades, Dr. Sabry Fattah brings a singular blend of scientific expertise and compassionate insight to his work. His forthcoming publication aims to connect the realms of science and humanity, providing valuable perspectives for readers worldwide.
Read more from Sabry Fattah
Minds Fading Away : Alzheimer's And Dementia Guide Rating: 5 out of 5 stars5/5"Artificial Intelligence: How Does It Work? And How to Use It?" Rating: 0 out of 5 stars0 ratingsWhen Body Speaks the Mind Rating: 0 out of 5 stars0 ratingsالاكتئاب : أنواعه وأسبابه وعلاجه Rating: 4 out of 5 stars4/5Depression and Mood Disorders: Causes, Care and Cures Rating: 0 out of 5 stars0 ratingsDepression and Bipolar Disorders : Causes, Care and Cures Rating: 0 out of 5 stars0 ratingsUnderstanding Python : Beginner's Guide to Programming Rating: 0 out of 5 stars0 ratingsSchizophrenia Rating: 0 out of 5 stars0 ratingsThe Hidden Mind Rating: 0 out of 5 stars0 ratingsAnxiety Explained: Managing Anxiety and Stress Problems Rating: 0 out of 5 stars0 ratingsAlcohol Problems : From Abuse to Recovery Rating: 0 out of 5 stars0 ratings
Related to Understanding Python
Related ebooks
Python Handbook For Beginners. A Hands-On Crash Course For Kids, Newbies and Everybody Else Rating: 0 out of 5 stars0 ratingsPython Made Simple: Learn Python programming in easy steps with examples Rating: 5 out of 5 stars5/5Python Rating: 0 out of 5 stars0 ratingsEasy-To-Follow Tutorial To Learn Python Programming In Less Than One Week Rating: 3 out of 5 stars3/5Programming with Python Rating: 0 out of 5 stars0 ratingsPython Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Useful Python Rating: 0 out of 5 stars0 ratingsPython Essentials Rating: 5 out of 5 stars5/5Python: Best Practices to Programming Code with Python: Python Computer Programming, #2 Rating: 0 out of 5 stars0 ratingsPython: Beginner's Guide to Programming Code with Python: Python Computer Programming, #1 Rating: 0 out of 5 stars0 ratingsPython In - Depth: Use Python Programming Features, Techniques, and Modules to Solve Everyday Problems Rating: 0 out of 5 stars0 ratingsModular Programming with Python Rating: 0 out of 5 stars0 ratingsLearn Python in 7 Days Rating: 0 out of 5 stars0 ratingsThe Ultimate Python Programming Guide For Beginner To Intermediate Rating: 4 out of 5 stars4/5Python for Beginners: Learn It as Easy as Pie Rating: 0 out of 5 stars0 ratingsPython: Advanced Guide to Programming Code with Python: Python Computer Programming, #4 Rating: 0 out of 5 stars0 ratingsMastering Python Advanced Concepts and Practical Applications Rating: 0 out of 5 stars0 ratingsPython: Beginner's Guide to Programming Code with Python Rating: 0 out of 5 stars0 ratingsData Science with Machine Learning - Python Interview Questions: Python Interview Questions Rating: 0 out of 5 stars0 ratingsPython for Beginners: Learn the Fundamentals of Computer Programming Rating: 0 out of 5 stars0 ratingsMastering Python: A Journey Through Programming and Beyond Rating: 0 out of 5 stars0 ratingsPython 3 Programming: A Beginner Crash Course Guide to Learn Python 3 in 1 Week Rating: 3 out of 5 stars3/5Python Programming: A Hands-On Guide: Hello World E-books STEM, #1 Rating: 0 out of 5 stars0 ratingsLearn Python in One Hour: Programming by Example Rating: 3 out of 5 stars3/5
Programming For You
Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsPython: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Learn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5Java: Programming: Your Step by Step Guide to Easily Learn Java in 7 Days Rating: 4 out of 5 stars4/5iMac For Dummies Rating: 0 out of 5 stars0 ratingsBeginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratingsPYTHON PROGRAMMING Rating: 4 out of 5 stars4/5Teach Yourself C++ Rating: 4 out of 5 stars4/5Beginning Programming with Python For Dummies Rating: 3 out of 5 stars3/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5
Reviews for Understanding Python
0 ratings0 reviews
Book preview
Understanding Python - Sabry Fattah
UNDERSTANDING PYTHON
Beginner’s Guide to Programming
***
Dr Sabry Fattah
Published by Sabry Fattah at Smashwords
Copyright 2020 Sabry Fattah
Table of Contents
Introduction
What is Programming?
Python Programming Language
Strings
Lists
Dictionary
Sets
Tuples
Iterators
Functions
Classes
Modules
Keywords
Builtins
The Regular Expressions
Files
Data
Documentation
Design
Example Script
Introduction
Many people hesitate to approach programming as they see it as a complex task which needs skills not easy to attain. Some believe you have to be good at mathematics to learn programming. For others, computers seem to be an enigma difficult to understand except by experts who have spent years studying at technical colleges.
In fact, programming is a skill every person should get his hands on. It does not need you to be a math wiz to program a computer. It only needs you to be able to think logically. Knowing how to program does not mean you are a software developer; it is mainly a necessity for every person in modern life. As we use software programs for every aspect of our daily life, we need to understand how these programs are designed and developed. In this way, not only that we understand fully how to use them efficiently, but also, we know what are their limitations and potentials.
Understanding software programming can also affect our way of thinking: how we identify and describe oue problems? how we analyse the problem’s parts? How to devise ways to manage such problems? And what logical steps to take to reach a solution to any problem?
Someone may ask: Why to bother with programming while there are thousands of software applications and programs available either free or for a little sum of money? Apart from those who would learn programming to promote their career and advance to a professional level, computer programming is very rewarding. To be able to customize a program to your needs and to design a simple script to perform exactly the task you want is very useful and satisfactory. If you are looking for subsiding your income with freelance online jobs in web design or data science, a good knowledge and experience in programming is essential.
This book is about computer programming using Python Programming Language. Python is a very popular language used in many academic institutions, schools, businesses, and corporations. It is known for its versatility, and ability to scale its use from the simplest programming task to the most complex and sophisticated project such as artificial intelligence.
This book is aimed at the general reader. However, you need to try the included code snippets given here to understand fully how they behave and perform their tasks. A hands-on approach is very essential in learning computer programming. After installing Python on your computer - if it is not already installed - you can try the interactive system on the windows console, which is the text-only mode window. You get to this window if you type cmd
at the Windows search box and clicking on the black icon. If you type python
at the prompt - provided you installed Python correctly - you will be at the Python Interactive Mode prompt. You can try simple statements here. Another way to test your code is to write a simple text file with extension .py
and run this file from the console.
I use python on Microsoft Windows. To test a script, I create a cmd.exe
shortcut on my desktop. This shortcut can be customized to point to the directory where my trial scripts are located. So, once I open the shortcut and get to the console window, I can write the name of the script to run it and see its output. The advantage for this approach is that you get a feedback about your errors. You can thus open two windows, one for the console and the other for your editor where you correct your code.
There is an editor bundled with Python installation known as IDLE which is short for Integrated Development and Learning Environment. It has two main windows, the Shell window and the Editor window. In this Interface, you are also able to run the code and notice output or any errors.
There are a number of available IDLE similar to the one available in Python installation. I prefer to use an advanced text editor like Notepad++ which allow code highlighting to identify different parts of the code text. Notepad++ also has a number of plugins which allow running your code and getting the output on the same screen. There is a learning curve in the process of mastering programming. The learning curve is not very steep with Python because it is easy to understand what exactly you are try to achieve and where are you mistakes. The following chapters will help you progress along these steps.
What is Programming?
Programming is writing computer code to create a program.
The aim of such program is to solve a problem. From a simple mathematical problem such as: How many even numbers in a series of numbers?
to a more complex one, e.g. How to recognize the faces of people in photos?
.
Programs consist of a series of instructions to tell a computer exactly what to do and how to do it. This is called an algorithm. An algorithm is a sequence of logical instructions to carry out a task. It is something similar to a recipe in cooking.
An algorithm may be written in plain English which could be a planning step before writing the true code. This is called a Pseudocode. Sometimes, a flow chart may be used to represent the steps in an algorithm to carry out the tasks. A pseudocode or a flow chart may be later translated into a computer program in the chosen programming language.
To program a computer, you need to communicate with the machine using a language it understands. The computer understands only machine code. You need a translator to help you get in contact with your computer. This translator is the programming language.
A programming language is an artificial language that communicate with the computer structure to control its output. Any such language is made up of series of statements that give instructions to tell a computer what to do.
Programming languages are designed to be easy for a human to understand and write in. However, a computer cannot run programs written in these languages directly. Most programming languages have to be translated into machine code before the computer can execute the instructions.
There are many different programming languages. They all share similar basic concepts although they differ in syntax and style. Some are more complicated and complex than others. Some are easier to understand for the human reader while others use concise, laconic and symbolic vocabulary.
Programming languages also differ in how they communicate with the computer structure, some are compiled and other are interpreted. A compiled language is a programming language which use a compiler (translator program) to generate machine code from source code. The source code is compiled before it is run. Interpreted language uses an interpreter (step-by-step executor program) to generate machine code from source code during the running of the written code. Each type has its advantages and disadvantages.
Among the most popular languages are:
1- Python: an interpreted, high-level and general-purpose programming language
2- Java : a compiled language which is interpreted into bytecodes before being compiled
3- C++ : a compiled programming language.
PYTHON Programming Language
Python is an interpreted, high-level and general-purpose programming language. This means it uses an interpreter which translate each statement into machine code before it is executed. There are different interpreters for the various operating systems available. Python is already installed in Linux and Unix systems, while it needs to be downloaded and installed in Windows.
Python was first released in 1991 by the Dutch programmer Guido van Rossum.
It is characterized by Readability: The reader can easily understand the meaning of the written code. Its syntax is similar to English language.
Python uses Indentation. This means that code blocks and statements are defined with whitespace indentation rather than semicolon or curly-bracket like other languages.
So, in C++ to print out Hello World
you would use this code:
#include
int main() {
cout << Hello World!
; return 0;
}
in Python you write:
print(Hello World
)
Python is concise in its syntax allowing users to express a complex task in few lines of code. As an interpreted language, the program is executed one line at a time, which makes correcting errors (debugging) easier.
Python is portable, so