0:00

In this video, we'll cover Expressions and Variables.

Â Expressions describe a type of operation the computers perform.

Â Expressions are operations the python performs, for example,

Â basic arithmetic operations like adding multiple numbers.

Â The result in this case is 160.

Â We call the numbers operands and the math symbols in this case,

Â addition, are called operators.

Â We can perform operations such as traction using the subtraction sign.

Â In this case the result is a negative number.

Â We can perform multiplication operations using the asterisk, The result is 25.

Â In this case, the operands are given by negative and asterisk.

Â We can also perform division with the forward slash.

Â 25 / 5 is 5.0.

Â 25 / 6 is approximately 4.167.

Â In Python 3 the version we will using in this course, both will result in a float.

Â We can use double slash for integer division, where the result is rounded.

Â Be aware, in some cases the results are not the same as regular division.

Â Python follows mathematical conventions when performing mathematical expressions.

Â The following operations are in a different order.

Â In both cases Python performs multiplication

Â then addition to obtain the final result.

Â There are a lot more operations you can do with Python, check the labs for

Â more examples.

Â We will also be covering more complex operations throughout he course.

Â The expressions in the parenthesis are performed first.

Â We then multiply the result by 60.

Â The result is 1,920.

Â Now, let's look at variables.

Â We can use variables to store values, in this case, we assign a value of 1 to

Â the variable my_variable using the assignment operator, i.e, the equal sign.

Â We can then use the value somewhere else in the code

Â by typing the exact name of the variable.

Â We will use a colon to denote the value of the variable.

Â We can assign a new value to my_variable using the assignment operator.

Â We assign a value of 10, the variable now has a value of 10.

Â The old value of the variable is not important.

Â We can store the results of expressions, for example, we add several values and

Â assign the result to x, x now stores the result.

Â We can also perform operations on x and save the result to a new variable, y.

Â Y now has a value of 2.666.

Â We can also perform operations on x and assign the value x.

Â The variable x now, has a value, 2.666.

Â As before, the old value of x is not important.

Â We can use the type command in variables as well.

Â It's good practice to use meaningful variable names, so

Â you don't have to keep track of what the variable is doing.

Â Let say, we would like to convert the number of minutes

Â in a highlighted examples to number of hours in the following music dataset.

Â We call the variable that contains the total number of minutes total_min.

Â It's common to use the underscore to represent the start of a new word,

Â you could also use a capital letter.

Â We call the variable that contains the total number of hours, total_hour.

Â We can obtain the total number of hours by dividing total_min by 60.

Â The result is approximately 2.367 hours.

Â If we modify the value of the first variable,

Â the value of the variable will change.

Â The final result values change accordingly, but

Â we do not have to modify the rest of the code.

Â