You may have heard about constructors if you have worked with programming languages before.
If not, let me explain.
Constructors are a special type of functions in that they are executed only once in the code's lifetime.
In case of smart contract, it is a function that is executed only when a contract is created and never after that, which means it essentially initializes the entire contract.
As an example, if you want to run some code on a contract, but if you also want to make sure that certain values are already set, that's when you will use a constructor.
So as you read, it is only executed in contract creation and no other case.
Right here we have an example of a constructor.
We have a uint which is public and its name is 'num'.
The constructor is right here with its syntax.
You use the keyword constructor just as you use the keyword function.
However, you don't give a name, you simply add brackets inside it.
If you want to add some arguments, you can or you can keep it blank as well.
But here we have given an argument called _num, which essentially sets the value of the state variable to whatever we add here, which means that when I execute a contract with this constructor, the value of num will be set to whatever I add into this.
Constructors are specifically use by contracts for certain types of functions.
For example to set an owner of the contract.
We should take a look at this in a bit more practical manner in remix IDE.