Declaration is when you declare a variable, function, method, class or similar thing.
Instruction is that where you instruct the program to perform a certain action.
Statements are usually not considered instructions because they say something that explains to the compiler or interpreter where certain data is recorded or what format it is. It’s not usually something to be directly executed that will have some sort of effect somewhere.
The instructions are things to be executed at certain times and that have some kind of effect: change values of variables, allocate or (depending on the language) displace memory, modify the state of the execution stack, perform some type of input or output, etc. Statements do not do this, as they are not executable, they only give names to some things.
It is true that you may have something like this depending on the programming language:
var x = 123;
In that case, the declaration shall be var x
and the initialization is the x = 123
. Initialization is an assignment type that is an instruction type. In this case, this line contains a statement and an instruction. They could be separated with this equivalent:
var x;
x = 123;
In Python specifically, the use of class MinhaClasse:
is a class statement, while def meu_metodo():
is a method statement. Python does not require the declaration of variables in other cases, but these are required in other programming languages, especially those that have static typing, such as C, C++, Java, C#, Pascal, Delphi, Rust and many others.
Are you only interested in Python-restricted responses specifically or do you want something broader to address how statements and statements are handled in most programming languages (which treat them very similarly)? In any case, my reply should address both cases.
– Victor Stafusa
Can you say in English the meaning of these words? Because I think you’re talking about statement and not declaration, which gives a completely different answer. In Brazil we misread these terms.
– Maniero