In Python they don't have to declare these types of debatable ahead of time like we do in DC.
Language the interpreter automatically detects the type of the variable by the data it contains in order
to assign a value to a variable B use d equals sign here which is known as the assignment operator and
if you try to access a variable that has not been assigned a value the program draws an error.
So let's see this in the python share here in the python shell.
I will try to squirt a ready bill that has not been assigned a value and see what is going to happen
here.
So I would say X days to the power all two and then hit enter so the program has thrown an error saying
name X is non defined.
So this means Python encounters a name or a variable that it does not recognize and this is the reason
we get the name error the next topic that we want to discuss is simultaneous assignment.
Python allows simultaneous assignments and the syntax is something like this and this statement dated
Python to evaluate all of the expressions on the right hand side and then assign them to the corresponding
variables on the left.
So let us now see an example in the python shell.
Let us now define two variables x and y so X comma Y equal to four.
Fine hit in dirt.
Now let's see what value the red X contains more than Y is five and simultaneous assignments odd helpful
to swap y lose all two variables.
Say for example if we want to swap the values into variables x and y you could do something like this.
Get them to put on a T.
What value does X contain X has five.
What would y y contains for.
Yeah do the arithmetic operators that we use in python like addition subtraction multiplication modulo
exponent flawed division set of if you try to divide number by 0.
Python raises and edit and the script is interrupted so let's say we try to do Y number 20 by 0.
As you can see here Python has raised and added zero division it has raised instead of just showing
the message exception needed Python dictated what type of exception it was encountered in our case it
is zero division.
Edit and Python comes with wedges built and exceptions as well as the possibility to create self defined
exceptions.
Until now we have discussed about various arithmetic operators such as addition subtraction division
flawed division etc..
That is not the.
Arithmetic operator that which is known as the modulo operator and suppose you want to find the remainder
then using division you can use the modulo operator.
Say for example you want to divide the number nine by two.
If you use the division operator you get the quotient.
If you want to know the remainder use the modulo operator and the symbol for this is percentage sign.
So 1 is the remainder when you divide 9 by 2 13 modulo offering 2 3.
So here you get the domain to then using the modulo operator.