Intro to Python Programming with Mosh – Pt. 03

April 7, 2019

Intro to Python Programming

Tutorial – 03

Youtube – Learn Python 3 for Machine Learning & Web Development [2019]

By: Programming with Mosh
Progress

End Time: 1:16:25

Next Part of Tutorial: Project: Weight Converter

NOTES

Arithmetic Operations

In Python we have the same operations used in math, as well as a few extra ones. There is addition, subtraction, multiplication, and division.

Here are a few of the extra operators. By using //, it returns the integer of the division with no remainder. Using the modulus, %, it returns the remainder after performing the division. Finally, ** is exponent, so this will raise a number to the other values power.

Then there is the augmented assignment operator. This is done by placing the operator directly before the equal sign. For example:

x += 3
is the same as: x = x + 3

Operator Precedence

This is the math concept where certain operations are performed before other operations. Many of these in Python are the same as those in basic math.

Math Functions

This just covers so more basic math functions: round, abs

Round rounds your value to the nearest integer. Abs returns the absolute value of a number.

If you want to do very intense mathematical calculations, you will want to grab a math module to add to Python. This module would give you more built in functions to perform mathematical functions. This is done by typing:

import math

at the top of your Python code. You can then call functions from it in your code with math.FUNCTIONNAME.

if Statements

The syntax of if statements is a bit different from C#. The syntax is as follows:

if STATEMENT:
functionsToPerform()

A colon is used to end the if conditional, and the functions following it are determined just by the indentation. To end the statement, you just remove the indent.

To perform else if, you simply type elif in Python. Else remains the same as you type the full word.

Logical Operators

These are the AND, OR, and NOT operators. In Python, logical AND, OR, and NOT are done by simply typing the word “and”, “or”, or “not” in the place they are needed. They do not use symbols.

Comparison Operators

These are used to compare variables with values. These are operators such as greater than and less than. These are all the same as C#, including the equivalency operator that is ==. Not equal is also the same, which is !=.