Expressions
Expressions are a fundamental concept that's quite overlooked when teaching the basics of programming. I've tried to tutor many students and it seems that nobody really mentions the term when teaching, so here's a short explanation of what expressions are just in case y'all need one :)
Here's a definition of what the term expression means:
An expression is a combination of values, variables, operators, and function calls that can be evaluated to produce a single value.
In Python, an expression can take a variety of forms, including:
Most programming languages have similar styles of expressions, even if the syntax is a bit different. Here's some more examples:
Rust:
Golang:
Perl:
Expressions can use a variety of operators to combine values and perform calculations. Some common operators include:
Arithmetic operators (
+
,-
,*
,/
,%
)Comparison operators (
==
,!=
,>
,<
,>=
,<=
)Logical operators (
and (&&)
,or (||)
,not (!)
)Bitwise operators (
&
,|
,^
,~
,<<
,>>
)Assignment operators (
=
,+=
,-=
,*=
,/=
,%=
,&=
,|=
,^=
,<<=
,>>=
)Unary operators (
+
,-
,not (!)
,~
)
The syntax and precedence of operators can vary between programming languages. Operator precedence determines the order in which operations are performed when an expression has multiple operators. In programming, different operators have different levels of precedence, which determines their order of evaluation. You'll have to check the programming language's documentation for a better reference :P
Last updated