How to Code With Python (1)
How to Code With Python (1)
Glossary
Python Essentials 1
- Computers can perform very complex tasks, but this ability is not innate.
- A computers nature is quite different.
>
>
- Contemporary computers can only evaluate the results of very fundamentals operations, like
adding or dividing, but they can do it very fast, and can repeat these actions virtually any numbers of
times.
>
>
- Imagine that you want to know the average speed you’ve reached during a long journey.
- You know the distance, you know the time, you need the speed.
>
- Naturally, the computer will be able to compute this, but the computer is not aware of such things
>
- Of course, these examples are not formalized, and they are very far from what the computer can
understand, but they are good enough to be translated into a language the computer can accept.
>
- Some of them require neither speaking nor writing, such as a body language; it’s possible to
>
- Another language you can use each day is your mother tongue, which you use to manifest your will
and to ponder reality.
- Computers have their own language too, called machine language, which is very rudimentary.
>
- A computer, even the most technically sophisticated, is devoid of even a trace of intelligence.
- You could say that it is like a well – trained – dog; it responds only to a predetermined set of known
commands.
- We can imagine that the computer responds to orders like “take the number, divide by another
and save the result.”
>
>
- A complete set of known commands is called an instruction list, sometimes abbreviated to IL.
- Different types of computers may vary depending on the size of their ILs, and the instructions could
be completely different in different models.
>
- Just as people use a number of very different languages, machines may have different languages
too.
- The difference, though, is that human languages developed naturally.
>
>
- Moreover, they are still evolving, and new words are created every day as old words disappear.
Compilation vs Interpretation
- Computer programming is the act of composing the selected programming language elements in
the order that will cause the desired effect.
- The effect could be different in every specific case – it’s up to the programmer’s imagination,
knowledge, and experience.
>
- Of course, such a composition has to be correct in many series:
Alphabetically – A program needs to be written in a recognizable script, such as Roman,
Cyrillic, etc.
Lexically – Each programming language has its dictionary, and you need to master it;
thankfully, its much simpler and smaller than the dictionary of any natural language.
Syntactically – Each language has its rules, and they must be obeyed.
Semantically – The program has to make sense.
>
- Unfortunately, a programmer can also make mistakes with each of the above four senses.
>
>
>
- There are very few languages that can be both compiled and interpreted.
- Usually, a programming language is projected with this factor in its constructor’s minds – will
it be compiled or interpreted?
- The interpreter reads the source code in a way that is common in western culture: from top to
>
- First of all, the interpreter checks if all subsequent lines are correct (using the four aspects
covered earlier).
>
>
>
- The interpreter will inform you where the error is located and what caused it.
- However, these messages may be misleading, as the interpreter isn’t able to follow your exact
intentions, and may detect errors at some distance from their real causes.
>
- For example, if you try to use an entity of an unknown name, it will cause an error, but the error
will be discovered in the place where it tries to use the entity, not where the new entity’s name
was introduced.
>
- In other words, the actual reason is usually located a little earlier in the code, for example, in the
place where you had to inform the interpreter that you were going to use the entity of the name.
>
- If the line looks good, the interpreter tries to execute it (note: each line is usually executed
separately, so the trio “read – check – execute” can be repeated many times more than the actual
number of the lines in the source file, as some parts of the code may be executed more than once)
>
- It is also possible that a significant part of the code may be executed successfully before the
>
- the execution of the translated - you can run the code as soon as you
complete it, there are no additional
code is usually faster
phases of translation
- only the user has to have the compiler,
-the code is stored using programming
the end user may use the code without language, this means that it can be run
it on computers using different machine
languages; you don’t compile your code
- the translated code is stored using separately for each different
machine language – as it is very hard to architecture.
understand it, your own inventions and
programming tricks are likely to remain a
secret.
DISADVATAGES
- the compilation itself may be a very - don’t expect interpretation to ramp up
time – consuming process; you may not your code to high speed; your code will
be able to run your code immediately share the computers power with the
after making an amendment interpreter, so it can’t be really fast
- you have to have so many compilers as - both you and the end user have to have
hardware platforms you want your code the interpreter to run you code.
to be run on.
>
>
Python is an interpreted language. This means that it inherits all the described advantages
and disadvantages. Of course, it adds some of its unique features to both sides.
If you want to program in Python, you’ll need the Python Interpreter. You won’t be able to
run your code without it. Fortunately, Python is free. This is one of its most important
advantages.
>
- Due to historical reasons, languages designed to be utilized in the interpretation manner are
often called scripting languages, while the source programs encoded using them are called scripts.
- Python is a widely – used, interpreted, object – oriented, and high – level programming language
with dynamic semantics, used for general purpose programming.
>
- And while you may know the python as a large snake, the name of the Python programming
language comes from an old BBC television comedy sketch called Monty Python Flying Circus.
>
- At the height of its success, the Monty Python team were performing their sketches to live
audiences across the world, including at the Hollywood Bowl.
>
- Since Monty Python is considered one of the two fundamental nutrients to a programmer (the
other being pizza), Python’s creator named to language in honor of the TV show.
[ In December 1989, I was looking for a “hobby” programming around Christmas. My office (…)
would be closed, but I had a home computer, and not much else on my hands. I decided to write an
interpreter for the new scripting language I had been thinking about lately: a descendent of ABC
that would appeal to Unix /C hackers. I choose Python as a working title for the project, being in a
slightly irreverent mood (and a big fan of Monty Python’s Flying Circus).]
>
>
Python Goals
- In 1999, Guido van Rossum defined his goals for Python:
An easy and intuitive language just as powerful as those of the major competitors.
Open source, so anyone can contribute to its development.
Code that is as understandable as plain English.
Suitable for everyday tasks, allowing for short development times.
>
- After 20 years later, it is clear that all these intentions have been fulfilled.
- Some sources say that Python is the most popular programming language in the world, while
>
- Either way, it still occupies a high rank in the top ten of the PYPL, Popularity of Programming
>
- It’s a bright star in the programming firmament, and time spent learning Python is a very good
investment.
Python Rivals?
- Python has two different competitors, with comparable properties and predispositions.
Pearl – A scripting language originally authored by Larry Wall
Ruby -A Scripting language originally authored by Yukihiro Matsumoto
>
- The former is more traditional and more conservative than Python, and resembles some of the
>
- In contrast, the latter is more innovative and fuller of fresh ideas than Python.
>
- The internet is full of forums with infinite discussions on the superiority of these three over the
>
- It’s too hard, too time-consuming, too expensive, and too risky to migrate an old Python 2
application to a new platform, and it’s even possible that rewriting the code will introduce new
bugs into it.
- It’s easier, and more sensible, to leave these systems alone and to improve the existing
interpreter, instead of trying to work inside the already functioning source code.
>
>
- Python 3 isn’t just a better version of Python 2; it is a completely different language, although its
very similar to its predecessor.
- When you look at them from a distance, they appear to be the same, but when you look closely,
though, you notice a lot of differences.
>
- If you’re modifying an old existing Python solution, then its highly likely that it was coded in
Python 2.
- This is the reason Python 2 is still in use.
- There are too many existing Python 2 applications to discard it all together.
>
- Note: If you’re going to start a new Python project, you should use Python 3, and this is the
version on Python that will be used further ahead.
>
- It is important to remember that there may be smaller or bigger differences between subsequent
Python 3 releases (e.g., Python 3.6 introduced ordered dictionary keys by default under the
CPython implementation); the good news, is that all the newer versions of Python 3 are backward
compatible with the previous versions of Python 3.
>
- All the code samples you will find during this course have been tested against Python 3.4, Python
3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9.
Python Implementations
-