Expressions and Operators in Python | Programming for Beginners

Publicado el: 25 agosto 2021
en el canal de: choobtorials
3,230
23

In this lesson, we are going to learn how to write expressions in Python.

Let's begin by defining what an expression is. An expression is anything that evaluates into a value. So what does that mean in this case when we say the word evaluate. Let's take a look at an example. Here in the shell, I'll create a variable named x and make it equal to 5. And then I will type x, and I will press enter, and here we see that we get the value 5. So this is what it means when we say that an expression evaluates into a value. In other words, an expression is something that turns into or results in a value. So in this example, we can say that x is an expression, because it evaluates into the value 5. And in fact, 5 itself, or any other literal value, is also an expression. If we type 5 here in the shell, and press enter, it evaluates to 5. Yes it evaluates into the same value, but nonetheless, it evaluates into one, therefore, it is an expression. Here's another example that can be considered an expression - a function call. When we call a function, it results in a value, therefore, a function call is also an expression. Recall the type function from a previous lesson. This function allows us to check a value's type. We can check for the type of the value 5, for example, and when I press enter, here we see that the function call evaluates into this - a type object that tells us what the value's type is. So in this case, we see that the type of 5 is int. It's an integer.

Ok, so expressions come in many different forms as you’ve seen in these examples. But, as we've learned, what they all have in common, no matter what form they take, is that they evaluate into a value. In this lesson, we will focus on the types of expressions that make use of what are called operators. An operator is a symbol that allows a programmer to specify a process to be applied on values. One simple example that we’ve already seen in previous videos is the addition operator, which tells the program to add values. For example: 3 + 5. This is an expression that will perform an addition operation on the values 3 and 5. The end result is that it evaluates into the value8.

In this expression, the plus symbol is what we would call an operator. And these 2 values are what we would refer to as operands.

Twitter:   / choobtorials  

#python #learntocode


En esta página del sitio puede ver el video en línea Expressions and Operators in Python | Programming for Beginners de Duración hora minuto segunda en buena calidad , que subió el usuario choobtorials 25 agosto 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 3,230 veces y le gustó 23 a los espectadores. Disfruta viendo!