Python Course for IT Professional

Hey everyone welcome back to this blog on numbers in Python. We already briefly mentioned that there’s two main number types so we’re going to be working with throughout the course and that is integers which are whole numbers and floating point numbers which are numbers of a can learn basic python structure from techstack website.

We’re going to be exploring a little bit of basic math of python and then we’ll discuss how to create variables and assign them values. Let’s open up what you put in a book and get started. All right so before we actually start typing any code I wanted to briefly mention that if you ever want to toggle this toolbar or this header on or off you can just come here

Click View and then select toggle header or toggle toolbar to turn them on or off. And typically during blogs I’ll have them off. So we have as much space for coding as possible. Let’s start off by just going over some basic math which is pretty straightforward and it’s basically just using Python as calculator if you want to do it. It’s just an addition sign or a plus sign two plus one if you want to do subtraction that’s just a dash or a minus sign to minus one. You can use an asterisk for multiplication.

python for beginner

So two times two. And if you want to perform division that’s just a forward slash. So three divided by two is 1.5 OK. Now let’s take a little bit of time to discuss a mathematical operation that you may not have seen before. It’s the modular or Ma’at operator. And basically what this does it returns back the remainder after a division. For example if we were to do seven divided by four we get back one point seventy five.

And if you were to do this kind of using an elementary school mathematics you would say seven divided by four foregoer the seven one time with a remainder of three because four plus three seven. Let’s imagine actually just wanted to know that remainder the actual number three. In that case you can use the Mata operator which is a percent sign.

So we’re going to say 7 model four and it returns back three because seven divided by four it goes in at one time evenly with a remainder of three. So for example we could do 50 maade of five and if five goes to 50 evenly then we get back a remainder of 0 which is nice because it’s a way to check if a number is evenly divisible by another number.

That’s a really convenient check when you want to check if a number is even or not. So let’s imagine we have an odd number 23 and we want to know if it’s even or odd. Well it could just look at it but maybe some time in my code it’s disguised as a variable and I really need to quickly check if it’s even or odd one way I could do this is simply with a mod 2 and I know that if made to result in something other than 0 then we have an odd number because of have an even number.

Then when you divide it by two. There should be no remainder or the remainder should be zero. if you are looking for Advanced python course in delhi So that’s the operator again. It just gives you the back the remainder after you perform a division. Let’s continue with everything else about arithmetic. You can also perform powers so you can do something like two to the power of three. So that’s just two Astrix signs in a row.

So to the power three That’s eight. And then you can also perform order of operations. Let’s imagine that I have the following equation 2 plus 10 multiplied by 10 plus three. If I run that could I get back 105. But what if I wanted to actually have two plus 10 occur first then multiply that by the result of 10 plus three. Right now we’re following basic order of operations with math which is going to perform this multiplication first before it does this addition.

So is performing ten times ten hundred plus two plus three. So our operations happen first the way we want them.

We can use parentheses. I can say two plus 10 multiplied by an imprint sees 10 plus three. And if I run that I get back 156 the way I want it. OK so that’s the basics of arithmetic and using Python as a calculator.

Hopefully it is pretty straightforward. Coming up next we’re going to expand on this by showing you how you can perform variable assignments that is create your own variable name and then assign an object to it. We’ll see you there at the next blog. 

Leave a Reply

Your email address will not be published. Required fields are marked *