THEORY
|
PAGE 1 / 1
|
What does a language consist of?
The vocabulary of any programming language consists of:- character set;
- identifiers;
- separators;
- comments.
Character set
The set of characters you can use to make a program in Python 3:- uppercase and lowercase letters of the English alphabet (A - Z, a - z);
- numbers from 0 to 9;
- special characters (+, -, *, /, =, ^, <, >, (, ), [, ], {, }, ., ,, :, ;, #, $, @, _ and blank).
Example 1. In Python 3 we can write like this, unlike other programming languages:
greece = "αβγδεζηθικλμνξοπρςστυφχψ"
print(greece)
print("î ă â ş ţ")
print("Hei! 😉")
Identifiers
By identifiers we mean a sequence of letters, numbers, or the special character "_", provided that the first is not a digit. With the help of identifiers, the names of variables, functions, etc. are associated.Example 2. Look at the statements of the following variables:
var1 = "mom"
var2 = "dad"
a_string = "a family"
As counterexamples, we have "1var", "str&". The first starts with a number, and the second contains a special character.
A special category of identifiers is given by the keywords of the Python 3 language (have a well-defined 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
and they must be written exactly as above to be interpreted correctly.
Python distinguishes between uppercase and lowercase letters. priNt("Hello!") gets a syntax error because the interpreter does not know the command priNt, but only print.
Separators
Definition. The simplest elements made up of characters with linguistic significance are called lexical units.They are separated, as appropriate, by one or more spaces, the end-of-line character, or the ";" character, as already presented.
Example 3. ab may mean the name of a variable, so we have a lexical unit, while a b contains two units...
Comments
Python encourages the introduction of comments in our code, as it is much easier to understand later. As you can see, they can be entered anywhere in the program, starting with the hash character ("#") and continuing to the end of the line.Example 4. Below is a comment in Python:
#this is a comment
The Python language is very sensitive to syntax and is strongly oriented towards a text arrangement that allows easy understanding of the code.
home | list LESSONS | arrow_upward |