What is Python?
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 series called Monty Python's
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 the language in honor of the TV show.
1.2.2 Who created Python?
One of the amazing features of Python is the fact that it is actually one person's work. Usually,
new programming languages are developed and published by large companies employing lots of
professionals, and due to copyright rules, it is very hard to name any of the people involved in
the project. Python is an exception.
There are not many languages whose authors are known by name. Python was created by Guido
van Rossum, born in 1956 in Haarlem, the Netherlands. Of course, Guido van Rossum did not
develop and evolve all the Python components himself...
The speed with which Python has spread around the world is a result of the continuous work of
thousands (very often anonymous) programmers, testers, users (many of them aren't IT
specialists) and enthusiasts, but it must be said that the very first idea (the seed from which
Python sprouted) came to one head – Guido's.
1.2.3 A hobby programming project
The circumstances in which Python was created are a bit puzzling. According to Guido van
Rossum:
In December 1989, I was looking for a "hobby" programming project that would keep me
occupied during the week 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 descendant of ABC that would appeal to Unix/C
hackers. I chose Python as a working title for the project, being in a slightly irreverent mood (and
a big fan of Monty Python's Flying Circus). Guido van Rossum
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.
About 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 others claim it's the
second or the third.
Either way, it still occupies a high rank in the top ten of the PYPL PopularitY of Programming
Language and the TIOBE Programming Community Index.
Python isn't a young language anymore. It is mature and trustworthy. It's not a one-hit wonder.
It's a bright star in the programming firmament, and time spent learning Python is a very good
investment.
1.2.4 What makes Python so special?
Why Python?
How does it happen that programmers, young and old, experienced and novice, want to use it?
How did it happen that large companies adopted Python and implemented their flagship products
using it?
There are many reasons – we've listed some of them already, but let's enumerate them again in a
more practical manner:
it's easy to learn - the time needed to learn Python is shorter than for many other
languages; this means that it's possible to start the actual programming faster;
it's easy to teach - the teaching workload is smaller than that needed by other languages;
this means that the teacher can put more emphasis on general (language-independent)
programming techniques, not wasting energy on exotic tricks, strange exceptions and
incomprehensible rules;
it's easy to use for writing new software - it's often possible to write code faster when
using Python;
it's easy to understand - it's also often easier to understand someone else's code faster if
it is written in Python;
it's easy to obtain, install and deploy - Python is free, open and multiplatform; not all
languages can boast that.
1.2.5 Python rivals?
Python has two direct competitors, with comparable properties and predispositions. These are:
Perl – 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
old languages derived from the classic C programming language.
In contrast, the latter is more innovative and more full of fresh ideas than Python. Python itself
lies somewhere between these two creations.
The Internet is full of forums with infinite discussions on the superiority of one of these three
over the others, should you wish to learn more about each of them.
1. Literals are notations for representing some fixed values in code. Python has various types of
literals - for example, a literal can be a number (numeric literals, e.g., 123), or a string (string
literals, e.g., "I am a literal.").
2. The binary system is a system of numbers that employs 2 as the base. Therefore, a binary
number is made up of 0s and 1s only, e.g., 1010 is 10 in decimal.
Octal and hexadecimal numeration systems, similarly, employ 8 and 16 as their bases
respectively. The hexadecimal system uses the decimal numbers and six extra letters.
3. Integers (or simply ints) are one of the numerical types supported by Python. They are
numbers written without a fractional component, e.g., 256, or -1 (negative integers).
4. Floating-point numbers (or simply floats) are another one of the numerical types supported
by Python. They are numbers that contain (or are able to contain) a fractional component,
e.g., 1.27.
5. To encode an apostrophe or a quote inside a string, you can either use the escape character,
e.g., 'I\'m happy.', or open and close the string using an opposite set of symbols to the ones you
wish to encode, e.g., "I'm happy." to encode an apostrophe, and 'He said "Python", not
"typhoon"' to encode a (double) quote.
6. Boolean values are the two constant objects True and False used to represent truth values (in
numeric contexts 1 is True, while 0 is False.
An expression is a combination of values (or variables, operators, calls to functions ‒ you will
learn about them soon) which evaluates to a certain value, e.g., 1 + 2.
Operators are special symbols or keywords which are able to operate on the values and perform
(mathematical) operations, e.g., the * operator multiplies two values: x * y.
Arithmetic operators in Python: + (addition), - (subtraction), * (multiplication), / (classic division
‒ always returns a float), % (modulus ‒ divides left operand by right operand and returns the
remainder of the operation, e.g., 5 % 2 = 1), ** (exponentiation ‒ left operand raised to the
power of right operand, e.g., 2 ** 3 = 2 * 2 * 2 = 8), // (floor/integer division ‒ returns a number
resulting from division, but rounded down to the nearest whole number, e.g., 3 // 2.0 = 1.0)
A unary operator is an operator with only one operand, e.g., -1, or +3.
A binary operator is an operator with two operands, e.g., 4 + 5, or 12 % 5.
Some operators act before others - the hierarchy of priorities:
the ** operator (exponentiation) has the highest priority;
then the unary + and - (note: a unary operator to the right of the exponentiation operator
binds more strongly, for example 4 ** -1 equals 0.25)
then: *, /, and %,
and finally, the lowest priority: binary + and -.
Subexpressions in parentheses are always calculated first, e.g., 15 - 1 * (5 * (1 + 2)) = 0.
The exponentiation operator uses right-sided binding, e.g., 2 ** 2 ** 3 = 256.
1. A variable is a named location reserved to store values in the memory. A variable is
created or initialized automatically when you assign a value to it for the first time.
(2.1.4.1)
2. Each variable must have a unique name ‒ an identifier. A legal identifier name must be a
non-empty sequence of characters, must begin with the underscore(_), or a letter, and it
cannot be a Python keyword. The first character may be followed by underscores, letters,
and digits. Identifiers in Python are case-sensitive.
3. Python is a dynamically-typed language, which means you don't need
to declare variables in it. (2.1.4.3) To assign values to variables, you can use a simple
assignment operator in the form of the equal (=) sign, i.e., var = 1.
4. You can also use compound assignment operators (shortcut operators) to modify
values assigned to variables, for example: var += 1, or var /= 5 * 2.
5. You can assign new values to already existing variables using the assignment operator or
one of the compound operators, for example:
var = 2
print(var)
var = 3
print(var)
var += 1
print(var)
6. You can combine text and variables using the + operator, and use the print() function to
output strings and variables, for example:
1
2
3
var = "007"
print("Agent " + var)