0% found this document useful (0 votes)
41 views

Python Programming-1-28

This document provides an introduction to Python programming. It discusses what Python is, how to install Python and get started with programming in Python. It covers basic Python programming concepts like variables, functions, libraries and plotting. The document contains examples and exercises to learn Python programming.

Uploaded by

dyner24tests
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Python Programming-1-28

This document provides an introduction to Python programming. It discusses what Python is, how to install Python and get started with programming in Python. It covers basic Python programming concepts like variables, functions, libraries and plotting. The document contains examples and exercises to learn Python programming.

Uploaded by

dyner24tests
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Python

Programming
Hans-Petter Halvorsen

https://www.halvorsen.blog
Python Programming
Python Programming

Hans-Petter Halvorsen

2019
Python Programming
c Hans-Petter Halvorsen

August 12, 2020

ISBN:978-82-691106-4-7

1
Preface

Python is a popular programming language, and it is one of the most used pro-
gramming languages today.

Python works on all the main platforms and operating systems used today, such
Windows, macOS, and Linux.

Python is a multi-purpose programming language, which can be use for simu-


lation, creating web pages, communicate with database systems, etc.

My Blog/Web Site [1]:


https://www.halvorsen.blog

Here you find lots of technical resources about Technology, Programming, Soft-
ware Engineering, Automation and Control, Industrial IT, etc.

Here you find my Web page with Python resources:

https://www.halvorsen.blog/documents/programming/python/

These resources are a supplement to this textbook. Here you can download the
software, download code examples, etc.

This Textbook is written in LATEXusing Overleaf.

LATEXis a document preparation system used for the communication and publi-
cation of scientific documents.

2
For more information about LATEX:
https://www.latex-project.org

Overleaf is a web-bases LATEXsystem, meaning you can write your LATEXdocuments


in your web browser, you co-work and share documents with others.

For more information about Overleaf:


https://www.overleaf.com

Python Books

You find other Python textbooks within different domains on my Python Web
page:
https://www.halvorsen.blog/documents/programming/python/

Python Books:

• Python Programming - This is a textbook in Python Programming


with lots of Practical Examples and Exercises. You will learn the necessary
foundation for basic programming with focus on Python.

• Python for Science and Engineering - This is a textbook in Python


Programming with lots of Examples, Exercises, and Practical Applications
within Mathematics, Simulations, etc. The focus is on numerical calcu-
lations in mathematics and engineering. Necessary theory is presented in
addition to many practical examples.

• Python for Control Engineering - This is a textbook in Python Pro-


gramming with lots of Examples, Exercises, and Practical Applications
within Mathematics, Simulations, Control Systems, DAQ, Database Sys-
tems, etc. The focus is on the use of Python within measurements, data
collection (DAQ), control technology, both analysis of control systems
(stability analysis, frequency response, ...) and implementation of control
systems (PID, etc.). Required theory is presented in addition to many
practical examples and exercises in Python.
• Python for Software Development - This is a textbook in Python Pro-
gramming with lots of Examples, Exercises, and Practical Applications
within Software Systems, Software Development, Software Engineering,
Database Systems, Web Application Desktop Applications, GUI Applica-
tions, etc. The focus is on the use of Python for creating modern Software
Systems. Required theory is presented in addition to many practical ex-
amples and exercises in Python.

3
Programming
The way we create software today has changed dramatically the last 30 years,
from the childhood of personal computers in the early 80s to today’s powerful
devices such as Smartphones, Tablets and PCs.

The Internet has also changed the way we use devices and software. We still
have traditional desktop applications, but Web Sites, Web Applications and so-
called Apps for Smartphones, etc. are dominating the software market today.

We need to find and learn Programming Languages that are suitable for the
New Age of Programming.

We have today several thousand different Programming Languages today. I


guess you will need to learn more than one Programming Language to survive
in today’s software market.

You find lots of Programming Resources here:


https://www.halvorsen.blog/documents/programming/

Software Engineering
Software Engineering is the discipline for creating software applications. A
systematic approach to the design, development, testing, and maintenance of
software.

The main parts or phases in the Software Engineering process are:

• Planning

• Requirements Analysis
• Design
• Implementation
• Testing

• Deployment and Maintenance

You find lots of Software Engineering Resources here:


https://www.halvorsen.blog/documents/programming/softwaree ngineering/

4
5
Contents

I Getting Started with Python 10


1 Introduction 11
1.1 The New Age of Programming . . . . . . . . . . . . . . . . . . . 11
1.2 MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2 What is Python? 17
2.1 Introduction to Python . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.1 Interpreted vs. Compiled . . . . . . . . . . . . . . . . . . 18
2.2 Python Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2.1 Python Packages for Science and Numerical Computations 20
2.3 Anaconda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.4 Python Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4.1 Python IDLE . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4.2 Visual Studio Code . . . . . . . . . . . . . . . . . . . . . . 22
2.4.3 Spyder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.4.4 Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.4.5 PyCharm . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.4.6 Wing Python IDE . . . . . . . . . . . . . . . . . . . . . . 23
2.4.7 Jupyter Notebook . . . . . . . . . . . . . . . . . . . . . . 23
2.5 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.6 Installing Python . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.6.1 Python Windows 10 Store App . . . . . . . . . . . . . . . 24
2.6.2 Installing Anaconda . . . . . . . . . . . . . . . . . . . . . 24
2.6.3 Installing Visual Studio Code . . . . . . . . . . . . . . . . 24

3 Start using Python 26


3.1 Python IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.2 My first Python program . . . . . . . . . . . . . . . . . . . . . . 26
3.3 Python Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.4 Running Python from the Console . . . . . . . . . . . . . . . . . 27
3.4.1 Opening the Console on macOS . . . . . . . . . . . . . . . 28
3.4.2 Opening the Console on Windows . . . . . . . . . . . . . 29
3.4.3 Add Python to Path . . . . . . . . . . . . . . . . . . . . . 29
3.5 Scripting Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.5.1 Run Python Scripts from the Python IDLE . . . . . . . . 31
3.5.2 Run Python Scripts from the Console (Terminal) macOS 32
3.5.3 Run Python Scripts from the Command Prompt in Win-
dows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

6
3.5.4 Run Python Scripts from Spyder . . . . . . . . . . . . . . 33

4 Basic Python Programming 36


4.1 Basic Python Program . . . . . . . . . . . . . . . . . . . . . . . . 36
4.1.1 Get Help . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.2 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.2.1 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.2.2 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.2.3 String Input . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.3 Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.4 Python Standard Library . . . . . . . . . . . . . . . . . . . . . . 41
4.5 Using Python Libraries, Packages and Modules . . . . . . . . . . 42
4.5.1 Python Packages . . . . . . . . . . . . . . . . . . . . . . . 44
4.6 Plotting in Python . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.6.1 Subplots . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.6.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

II Python Programming 50
5 Python Programming 51
5.1 If ... Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.2 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
5.3 For Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.3.1 Nested For Loops . . . . . . . . . . . . . . . . . . . . . . . 57
5.4 While Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

6 Creating Functions in Python 60


6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6.2 Functions with multiple return values . . . . . . . . . . . . . . . 62
6.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

7 Creating Classes in Python 66


7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
7.2 The init () Function . . . . . . . . . . . . . . . . . . . . . . . . 67
7.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

8 Creating Python Modules 71


8.1 Python Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
8.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

9 File Handling in Python 74


9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
9.2 Write Data to a File . . . . . . . . . . . . . . . . . . . . . . . . . 74
9.3 Read Data from a File . . . . . . . . . . . . . . . . . . . . . . . . 75
9.4 Logging Data to File . . . . . . . . . . . . . . . . . . . . . . . . . 75
9.5 Web Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
9.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

7
10 Error Handling in Python 79
10.1 Introduction to Error Handling . . . . . . . . . . . . . . . . . . . 79
10.1.1 Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . 79
10.1.2 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . 79
10.2 Exceptions Handling . . . . . . . . . . . . . . . . . . . . . . . . . 80

11 Debugging in Python 82

12 Installing and using Python Packages 83


12.1 What is PIP? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

III Python Environments and Distributions 84


13 Introduction to Python Environments and Distributions 85
13.1 Package and Environment Managers . . . . . . . . . . . . . . . . 86
13.1.1 PIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
13.1.2 Conda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
13.2 Python Virtual Environments . . . . . . . . . . . . . . . . . . . . 87

14 Anaconda 88
14.1 Anaconda Navigator . . . . . . . . . . . . . . . . . . . . . . . . . 88

15 Enthought Canopy 90

IV Python Editors 91
16 Python Editors 92

17 Spyder 94

18 Visual Studio Code 96


18.1 Introduction to Visual Studio Code . . . . . . . . . . . . . . . . . 96
18.2 Python in Visual Studio Code . . . . . . . . . . . . . . . . . . . . 97

19 Visual Studio 98
19.1 Introduction to Visual Studio . . . . . . . . . . . . . . . . . . . . 98
19.2 Work with Python in Visual Studio . . . . . . . . . . . . . . . . . 98
19.2.1 Make Visual Studio ready for Python Programming . . . 99
19.2.2 Python Interactive . . . . . . . . . . . . . . . . . . . . . . 99
19.2.3 New Python Project . . . . . . . . . . . . . . . . . . . . . 100

20 PyCharm 106

21 Wing Python IDE 108

22 Jupyter Notebook 110


22.1 JupyterHub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
22.2 Microsoft Azure Notebooks . . . . . . . . . . . . . . . . . . . . . 111

8
V Python for Mathematics Applications 113
23 Mathematics in Python 114
23.1 Basic Math Functions . . . . . . . . . . . . . . . . . . . . . . . . 114
23.1.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
23.2 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
23.2.1 Introduction to Statistics . . . . . . . . . . . . . . . . . . 118
23.2.2 Statistics functions in Python . . . . . . . . . . . . . . . . 119
23.3 Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . 121
23.4 Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

VI Resources 128
24 Python Resources 129
24.1 Python Distributions . . . . . . . . . . . . . . . . . . . . . . . . . 129
24.2 Python Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
24.3 Python Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
24.4 Python Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
24.5 Python in Visual Studio . . . . . . . . . . . . . . . . . . . . . . . 130

VII Solutions to Exercises 133

9
Part I

Getting Started with


Python

10
Chapter 1

Introduction

With this textbook you will learn basic Python programming. The textbook
contains lots of examples and self-paced tasks that the users should go through
and solve in their own pace.

You will find additional resources on my blog/web site [1].


https://www.halvorsen.blog

My Web Site about Python is:


https://www.halvorsen.blog/documents/programming/python/

See Figure 1.1

1.1 The New Age of Programming


The way we create software today has changed dramatically the last 30 years,
from the childhood of personal computers in the early 80s to today’s powerful
devices such as Smartphones, Tablets and PCs.

The Internet has also changed the way we use devices and software. We still
have traditional desktop applications, but Web Sites, Web Applications and so-
called Apps for Smartphones, etc. are dominating the software market today.

We need to find and learn Programming Languages that are suitable for the
New Age of Programming.

We have today several thousand different Programming Languages, so why


should we learn Python? I guess you will need to learn more than one Pro-
gramming Language to survive in today’s software market. Python is easy to
learn, so it it a good starting point for new programmers.

Python is an interpreted, high-level, general-purpose programming language.


Created by Guido van Rossum and first released in 1991 [2].

11
Figure 1.1: Web Site - Python

Python is a fairly old Programming Language (1991) compared to many other


Programming Languages like C# (2000), Swift (2014), Java (1995), PHP (1995).

Python has during the last 10 years become more and more popular. Today,
Python has become one of the most popular Programming Languages.

There are many different rankings regarding which programming language which
is most popular. In most of these ranking, Python is in top 10.

One of these rankings is the IEEE Spectrum’s ranking of the top programming
languages [3].

From this ranking we see that Python is the most popular Programming Lan-
guage in 2018. See Figure 1.2
As we see in Figure 1.2 they categorize the different Programming Languages
into the following categories:

• Web

12
Figure 1.2: The Most Popular Programming Languages

• Mobile
• Enterprise

• Embedded
According to Figure 1.2 we see that Python can be used to program Web Ap-
plications, Enterprise Applications and Embedded Applications.

So far Python is not used or not optimized for creating Mobile Applications. We
have today 2 major Mobile platforms; iOS Applications are mainly programmed
with the Swift Programming language, while Android Applications are mainly
programmed with either Java or Kotlin.

Another survey is the ”Stack Overflow Developer Survey 2018” [4]. See Figure
1.3.

As we can see from [5] and Figure 1.4, Python becomes more and more popular
year by year.

Based on Figure 1.4, the source [5] try to predict the future of Python, see
Figure 1.5.

Based on the surveys and statistics mention above, obviously Python is a pro-
gramming language that you should learn.

Lets summarize:

• Python is fun to learn and use and it is also named after the British
comedy group called Monty Python.

• Python has a simple and flexible code structure and the code is easy to
read.

13
Figure 1.3: The Top Programming Languages - Stack Overflow Survey

• Python is highly extendable due to its high number of free available


Python Packaged and Libraries
• Python can be used on all platforms (Windows, macOS and Linux).
• Python is multi-purpose and can be used for to program Web Applications,
Enterprise Applications and Embedded Applications, and within Data
Science and Engineering Applications.

• The popularity of Python is growing fast.


• Python is open source and free to use
• The growing Python community makes it easy to find documentation,
code examples and get help when needed

In general, Python is a multipurpose programming language that can be used


in many situations. But there is not one programming language which is best
in all kind of situations, so it is important that you know about and have skills
in different languages.

My list of recommendations (one of many):


• Visual Studio and C

• LabVIEW - a graphical programming language well suited for hardware


integration, taking measurements and data logging
• MATLAB - Numerical calculations and Scientific computing
• Python - Numerical calculations, and Scientific computing, etc.

• Web Programming, such as HTML, CSS, JavaScript and a Server-side


framework/programming language like PHP, ASP.NET (C or VB.NET),
Django (Python based)

14
Figure 1.4: The Incredible Growth of Python

• Databases (such as SQL Server and MySQL) and using the Structured
Query Language (SQL) or the upcoming NoSQL databases
• App Development for the 2 main platforms iOS (XCode using the Swift
Programming Language) and Android (Android Studio using the Java
Programming Language or Kotlin Programming language)
If you have skills in most of the tools, programming languages and frameworks
mention above, you are well suited for working as a full-time programmer or
software engineer.

1.2 MATLAB
If you are looking for MATLAB, please see the following:
https://www.halvorsen.blog/documents/programming/matlab/

15
Figure 1.5: The Future of Python

16
Chapter 2

What is Python?

2.1 Introduction to Python


Python is an open source and cross-platform programming language, that has
become increasingly popular over the last ten years. It was first released in
1991. Latest version is 3.7.0. CPython is the reference implementation of the
Python programming language. Written in C, CPython is the default and most
widely-used implementation of the language.

Python is a multi-purpose programming languages (due to its many extensions),


examples are scientific computing and calculations, simulations, web develop-
ment (using, e.g., the Django Web framework), etc.

Python Home Page [6]:


https://www.python.org

The programming language is maintained and available from (Python Software


Foundation): https://www.python.org Here you can download the basic Python
features in one package, which includes the Python programming language in-
terpreter, and a basic code editor, or an integrated development environment,
called IDLE. See Figure 2.1

But this is just the Python core, i.e. the interpreter a very basic editor, and the
minimum needed to create basic Python programs.

Typically you will need more features for solving your tasks. Then you can in-
stall and use separate Python packages created by third parties. These packages
need to be downloaded and installed separately (typically you use something
called PIP), or you choose to use, e.g., a distribution package like Anaconda.

Python is an object-oriented programming language (OOP), but you can use


Python in basic application without the need to know about or use the object-
oriented features in Python.

Python is an interpreted programming language, this means that as a developer

17
Figure 2.1: IDLE - Basic Python Editor

you write Python (.py) files in a text editor and then put those files into the
python interpreter to be executed. Depending on the Editor you are using, this
is either done automatically, or you need to do it manually.

Here are some important Python sources: [6], [7], [8].

2.1.1 Interpreted vs. Compiled


What are the differences between Interpreted programming languages and Com-
piled programming languages? What kind should you choose, and why should
you bother?

Programming languages generally fall into one of two categories: Compiled or


Interpreted. With a compiled language, code you enter is reduced to a set of
machine-specific instructions before being saved as an executable file.
Both approaches have their advantages and disadvantages.

18
With interpreted languages, the code is saved in the same format that you en-
tered. Compiled programs generally run faster than interpreted ones because
interpreted programs must be reduced to machine instructions at run-time. It
is usually easier to develop applications in an interpreted environment because
you don’t have to recompile your application each time you want to test a small
section.

Python is an interpreted programming language, while e.g., C/C++ are trans-


lated by running the source code through a compiler, i.e., C/C++ are compiled
languages.

Interpreted languages, in contrast, must be parsed, interpreted, and executed


each time the program is run.

Another example of an interpreted programming language is PHP, which is


mainly used to create dynamic web pages and web applications.

Compiled languages are all translated by running the source code through a
compiler. This results in very efficient code that can be executed any number of
times. The overhead for the translation is incurred just once, when the source
is compiled; thereafter, it need only be loaded and executed.

During the design of an application, you might need to decide whether to use a
compiled language or an interpreted language for the application source code.

Interpreted languages, in contrast, must be parsed, interpreted, and executed


each time the program is run

Thus, an interpreted language is generally more suited for doing ”ad hoc” cal-
culations or simulations, while compiled languages are better for permanent
applications where speed is in focus.

2.2 Python Packages


With Python you don’t get so much out of the box. Instead of having all of
its functionality built into its core, you need to install different packages for
different topics.

This approach has advantages and disadvantages. An disadvantage is that you


need to install these packages separately and then later import these modules
in your code.

This is also typical approach for open source software, because everybody can
create their own Python packages and distribute them. In that way you also
find Python packages for almost everything, from Scientific Computing to Web
Development.

19
These packages need to be downloaded and installed separately, or you choose
to use, e.g., a distribution package like Anaconda, where you typically get the
packages you need for scientific computing. With Anaconda you typically get
the same features as with MATLAB.

Lots of Python packages exists, depending on what you are going to solve.
We have Python packages for Desktop GUI Development, Database Develop-
ment, Web Development, Software Development, etc.

See an overview of Applications for Python:


https://www.python.org/about/apps/

See also the Python Package Index (PyPI) web site:


https://pypi.org

Here you can search for, download and install many hundreds Python Packages
within different topics and applications. You can also make your own Python
Packages and distribute them here.

2.2.1 Python Packages for Science and Numerical Com-


putations
Some important Python Packages for Science and Numerical Computations are:
• NumPy - NumPy is the fundamental package for scientific computing
with Python [9]
• SciPy - SciPy is a free and open-source Python library used for scientific
computing and technical computing. SciPy contains modules for optimiza-
tion, linear algebra, integration, interpolation, special functions, FFT, sig-
nal and image processing, ODE solvers and other tasks common in science
and engineering. [9]
• Matplotlib - Matplotlib is a Python 2D plotting library. [10]

• Pandas - Pandas Python Data Analysis Library [11]


These packages need to be downloaded and installed separately, or you choose
to use, e.g., a distribution package like Anaconda, where you typically get the
packages you need for scientific computing. With Anaconda you typically get
the same features as with MATLAB.

2.3 Anaconda
Anaconda is a distribution package, where you get Python compiler, Python
packages and the Spyder editor, all in one package.

Anaconda includes Python, the Jupyter Notebook, and other commonly used
packages for scientific computing and data science.

20
They offer a free version (Anaconda Distribution) and a paid version (Enter-
prise) Anaconda is available for Windows, macOS, and Linux

Web:
https://www.anaconda.com

Wikipedia:
https://en.wikipedia.org/wiki/Anaconda( P ythond istribution)

Spyder and the Python packages (NumPy, SciPy, Matplotlib, ...) mention above
+++ are included in the Anaconda Distribution.

2.4 Python Editors


An Editor is a program where you create your code (and where you can run
and test it). Most Editors have also features for Debugging. For simple Python
programs you can use the IDLE Editor, but for more advanced programs a bet-
ter editor is recommended.

Examples of Python Editors:


• Python IDLE
• Visual Studio Code
• Spyder
• Visual Studio
• PyCharm
• Wing Python IDE
• Jupyter Notebook
These editors are shortly described below and in more detail later in this text-
book.

Which editor you should use depends on your background, what kind of code
editors you have used previously, your programming skills, what your are going
to develop in Python, etc.

2.4.1 Python IDLE


The programming language is maintained and available from (Python Software
Foundation): https://www.python.org Here you can download the basic Python
features in one package, which includes the Python programming language in-
terpreter, and a basic code editor, or an integrated development environment,
called IDLE. See Figure 2.1

Web:
https://www.python.org

21
2.4.2 Visual Studio Code
Visual Studio Code is a source code editor developed by Microsoft for Windows,
Linux and macOS.

Web:
https://code.visualstudio.com

Resources: Getting Started with Python in Visual Studio Code

2.4.3 Spyder
Spyder is an open source cross-platform integrated development environment
(IDE) for scientific programming in the Python language.

Web:
https://www.spyder-ide.org

Wikipedia:
https://en.wikipedia.org/wiki/Spyder( sof tware)

Spyder is included in the Anaconda Distribution.

2.4.4 Visual Studio


Microsoft Visual Studio is an integrated development environment (IDE) from
Microsoft. It is used to develop computer programs, as well as websites, web
apps, web services and mobile apps. The deafult (main) programming language
in Visual studio is C, but many other programming languages are supported.

Visual studio is available for Windows and macOS.

Visual Studio (from 2017), has integrated support for Python, it is called
”Python Support in Visual Studio”.

Web:
https://visualstudio.microsoft.com

Wikipedia:
https://en.wikipedia.org/wiki/MicrosoftV isualS tudio

2.4.5 PyCharm
PyCharm is cross-platform, with Windows, macOS and Linux versions. The
Community Edition is free to use, while the Professional Edition (paid version)
has some extra features.

22
Web:
https://www.jetbrains.com/pycharm/

2.4.6 Wing Python IDE


The Wing Python IDE family of integrated development environments (IDEs)
from Wingware were created specifically for the Python programming language.

3 different version of Wing exists [12]:

• Wing 101 – a very simplified free version, for teaching beginning pro-
grammers
• Wing Personal – free version that omits some features, for students and
hobbyists
• Wing Pro – a full-featured commercial (paid) version, for professional
programmers

2.4.7 Jupyter Notebook


The Jupyter Notebook is an open-source web application that allows you to cre-
ate and share documents that contain live code, equations, visualizations and
text.

Web:
http://jupyter.org

Wikipedia:
https://en.wikipedia.org/wiki/ProjectJ upyter

2.5 Resources
Here are some useful Python resources:
• The official Python Tutorial
- https://docs.python.org/3.7/tutorial/index.html
• The official Python Documentation
- https://docs.python.org/3.7/index.html
• Python Tutorial (w3schools.com) [13]
- https://www.w3schools.com/python/

2.6 Installing Python


The Python programming language is maintained and available from (Python
Software Foundation):

23
https://www.python.org

Here you can download the basic Python features in one package, which includes
the Python programming language interpreter, and a basic code editor, or an
integrated development environment, called IDLE. See Figure 2.1

For basic Python programming this is good enough.

For more advanced Python Programming you typically need a better Code Ed-
itor and additional Packages.

For the basic Python examples in the beginning, the basic Python software
from:
https://www.python.org is good enough.

I suggest you start with the basic Python software in order to learn the basics,
then you can upgrade to a better Editor, install addition Python packages (either
manually or or install Anaconda where ”everything” is included).

2.6.1 Python Windows 10 Store App


Python 3.7 is also available in the Microsoft Store for Windows 10.

The Microsoft Store version of Python 3.7 is a simplified installer for running
scripts and packages.

Microsoft Store version of Python 3.7 is very basic but it’s good enough to run
the simple scripts.

Python 3.7 Microsoft Store edition will receive all updates automatically when
they are released and no manual action is required from your end.

In order to install the Microsoft Store version of Python just open Microsoft
Store in Windows 10 and search for Python.

2.6.2 Installing Anaconda


The Spyder Code Editor and the Python packages (such as NumPy, SciPy, mat-
plotlib, etc) are included in the Anaconda Distribution.

Download and install from:


https://www.anaconda.com

2.6.3 Installing Visual Studio Code


Visual Studio Code code is a simple and easy to use editor that can be used for
many different programming languages.

24
Download and install from:
https://code.visualstudio.com

Getting Started with Python in Visual Studio Code:


https://code.visualstudio.com/docs/python/python-tutorial

25

You might also like