0% found this document useful (0 votes)
2 views2 pages

200336.036-en

The video explains expressions and variables in Python, detailing how to perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It emphasizes the use of variables to store values and the importance of meaningful variable names for clarity in coding. Additionally, it covers how to manipulate and reassign variable values while maintaining the integrity of the code structure.

Uploaded by

LUIS CALVO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

200336.036-en

The video explains expressions and variables in Python, detailing how to perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It emphasizes the use of variables to store values and the importance of meaningful variable names for clarity in coding. Additionally, it covers how to manipulate and reassign variable values while maintaining the integrity of the code structure.

Uploaded by

LUIS CALVO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

In this video, we will cover expressions and variables.

Expressions describe a type of operation that computers perform.


Expressions are operations that 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 subtraction 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 operations 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 be using in this course, both will result in a
float.
We can use the 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 the course.
The expressions in the parentheses 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 the highlighted examples to number of hours in the following music data-set.
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.
(Music)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy