About the Python Language Vocabulary
What does a language consist of?
The vocabulary of any programming language is composed of:
- a character set
- identifiers
- separators
- comments
The Character Set
The character set represents the collection of characters that can be used to create a program in Python, and it consists of:
- uppercase and lowercase letters of the English alphabet (A - Z, a - z);
- digits of the base-10 number system (0 - 9);
- special characters (+, -, *, /, =, ^, <, >,
(, ), [, ], {, }, ., ,, :, ;,
#, $, @, _, and blank (space)).
Unlike other programming languages, Python 3 directly supports character representation using the
[
Unicode] standard,
specifically in the [
UTF-8] format.
This means we can include characters not available on our keyboard by copying them from the Internet.
Therefore, we can use special characters and even
[
emoji]
or [
smileys].
Example 1. In Python, unlike other programming languages, we can write code like this:
grecesc = "αβγδεζηθικλμνξοπρςστυφχψ"
print(greece)
print("î ă â ş ţ")
print("Hey! 😉")
See more [
details about UTF-8].
Identifiers
Identifiers are understood as a
sequence of letters, digits, or the special character "
_",
provided that
the first character is not a digit. Identifiers are used to name
variables,
functions, etc.
Example 2. Observe the following variable declarations:
var1 = "mother"
var2 = "father"
a_string = "a family"
As counterexamples, we have "
1var" and "
string&". The first starts with a digit, and the second contains a special character.
A special category of identifiers is given by
Python keywords (these have a specific meaning, are reserved,
and cannot be used in another context). The complete list is as follows:
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
These must be written exactly as shown above to be interpreted correctly.
Python distinguishes between uppercase and lowercase letters.
priNt("Hello!") results in a
syntax error because the interpreter does not recognize the command
priNt, only
print.
Separators
Definition. The simplest elements made up of characters with linguistic significance are called
lexical units.
These are separated by
one or
more spaces, the
end of line character, or the character "
;", as already presented.
Example 3.
ab may signify the name of a variable, thus it is a lexical unit,
whereas
a b contains two units...
Comments
Python encourages adding comments to our code because it makes it much easier to understand later. As you have seen,
these can be added anywhere in the program, starting with the hash character ("
#") and continuing until the end of the line.
Example 4. Below is a comment written in Python:
#this is a comment
The Python language is very sensitive to syntax and is strongly oriented toward a writing style that allows easy
understanding of the code by another programmer who receives the program.
Remember these important details.
You also need to have a suitable programming language!