ad home

Treading on Python Series: Illustrated Guide to Python 3 2020

Which editor?
In addition to installing Python, you will need a text editor. An editor is a
tool for writing code. A skilled craftsman will invest the time to learn to use
their tool appropriately and it will pay dividends. Learning to use the
features of an editor can make churning out code easier. Many modern
editors today have some semblance of support for Python.
If you are just beginning with Python and have not had much experience
with real text editors, most Python installations include IDLE, which has
decent Python editing features. The IDLE development environment also
runs on Windows, Mac and Linux.
A feature to look for in editors is integration with the Python REPL 4
Later you will see an example with IDLE. Hopefully your editor of choice
will have similar features.
Popular editors with decent Python support include Emacs, Vim, Atom,
Visual Studio Code, and Sublime Text. If you are interested in more fancy
editors that have support for refactoring tools and intelligent completion,
PyCharm and Wing IDE are also popular.
Python 3 is the current version of Python. Unless you are working on
legacy code, you should favor using this version. You can find the latest
version on the Python website.
Most modern editors contain some support for Python. There are various
levels of features that editors and IDEs provide. If you are getting started
programming, give the IDLE editor a try. It is a great place to start out.
1. Install Python 3 on your computer. Make sure you can start Python.
2. If you are used to a particular editor, do some investigation into its
support for Python. For example, does it:
Do syntax highlighting of Python code?
Run Python code in a REPL for you?
Provide a debugger for stepping through your Python code?
1 -
2 -
3 -
4 - REPL stands for Read, Evaluate, Print, and Loop. You will soon see
an example using it.
The Interpreter
used to describe an interpreted language is scripting language. To run a
computer program on the CPU, the program must be in a format that the
CPU understands, namely machine code. Interpreted languages do not
compile directly to machine code, instead, there is a layer above, an
interpreter that performs this function.
There are pros and cons to this approach. As you can imagine, on the fly
translating can be time consuming. Interpreted code like Python programs
tend to run on the order of 10–100 times slower than C programs. On the
flip side, writing code in Python optimizes for developer time. It is not
uncommon for a Python program to be 2–10 times shorter than its C
equivalent. Also, a compilation step can be time consuming and actually a
distraction during development and debugging.
Many developers and companies are willing to accept this trade-off.
Smaller programs (read fewer lines of code) take less time to write and are
easier to debug. Programmers can be expensive—if you can throw
hardware at a problem, it can be cheaper than hiring more programmers.
Debugging 10 lines of code is easier than debugging 100 lines of code.
Studies have shown that the number of bugs found in code is proportional
to the numbers of lines of code. Hence, if a language permits you to write
fewer lines of code to achieve a given task, you will likely have fewer bugs.
Sometimes program execution speed is not that important and Python is
sufficiently fast for many applications. In addition, there are efforts to
improve the speed of Python interpreters such as PyPy 5
Python has an interactive interpreter or REPL (Read Evaluate Print Loop).
This is a loop that waits until there is input to read in, then evaluates it
(interprets it), and prints out the result. When you run the python3
executable by itself, you launch the interactive interpreter in Python. Other
environments, such as IDLE, also embed an interactive interpreter.

No comments:

Powered by Blogger.