0 added
0 removed
Original
2026-01-01
Modified
2026-02-21
1
<p>Let's keep looking at functions and their components. Today, we'll be looking at expressions. Let's discuss what it is and what is the difference between functions and expressions.</p>
1
<p>Let's keep looking at functions and their components. Today, we'll be looking at expressions. Let's discuss what it is and what is the difference between functions and expressions.</p>
2
<h2>What are expressions</h2>
2
<h2>What are expressions</h2>
3
<p>An expression in programming returns a result that we can use. You probably already know a lot about them and the principles of their construction.</p>
3
<p>An expression in programming returns a result that we can use. You probably already know a lot about them and the principles of their construction.</p>
4
<p>For example, addition, subtraction, and concatenation are all expressions:</p>
4
<p>For example, addition, subtraction, and concatenation are all expressions:</p>
5
<p>The peculiarity of expressions is that they return a result that we can use again: for example, they can be assigned to a variable or printed. It is what it looks like in the code:</p>
5
<p>The peculiarity of expressions is that they return a result that we can use again: for example, they can be assigned to a variable or printed. It is what it looks like in the code:</p>
6
<p>But not everything in programming is an expression. The definition of a variable is an instruction, which means it can't be part of an expression. In other words, this code will lead to an error:</p>
6
<p>But not everything in programming is an expression. The definition of a variable is an instruction, which means it can't be part of an expression. In other words, this code will lead to an error:</p>
7
<p>Let us see whether we can take a function call as an expression.</p>
7
<p>Let us see whether we can take a function call as an expression.</p>
8
<h2>Functions as expressions</h2>
8
<h2>Functions as expressions</h2>
9
<p>We know that functions return results, so they are expressions. It leads to a lot of possibilities. For example, we can use a function call directly in mathematical operations. It is how we can get the last character index in a word:</p>
9
<p>We know that functions return results, so they are expressions. It leads to a lot of possibilities. For example, we can use a function call directly in mathematical operations. It is how we can get the last character index in a word:</p>
10
<p>This code has no new syntax. We have merely connected parts we already know. We could go even further:</p>
10
<p>This code has no new syntax. We have merely connected parts we already know. We could go even further:</p>
11
<p>All of this applies to any function, e.g., string functions:</p>
11
<p>All of this applies to any function, e.g., string functions:</p>
12
<p>As you'll see later, we can combine expressions to produce increasingly complex behavior in different places. The more you learn and practice Python, the better you understand the topic. Over time, you'll learn how to connect code fragments to get the needed results.</p>
12
<p>As you'll see later, we can combine expressions to produce increasingly complex behavior in different places. The more you learn and practice Python, the better you understand the topic. Over time, you'll learn how to connect code fragments to get the needed results.</p>