Operators and Expressions in Edexcel A-Level Programming | Edexcel A-Level 编程中的运算符与表达式

📚 Operators and Expressions in Edexcel A-Level Programming | Edexcel A-Level 编程中的运算符与表达式

In Edexcel A-Level Computer Science, programming questions often test your ability to build and evaluate expressions correctly. Operators are the building blocks that combine values, variables, and function calls into meaningful computations. This revision guide covers arithmetic, relational, Boolean, bitwise, and assignment operators, as well as precedence, type conversion, and common exam traps.

在 Edexcel A-Level 计算机科学中,编程题经常考查你正确构建和求值表达式的能力。运算符是将值、变量和函数调用组合成有意义计算的基石。本复习指南涵盖算术、关系、布尔、位运算和赋值运算符,以及优先级、类型转换和常见考试陷阱。


1. Operators and Operands Overview | 运算符与操作数概览

An expression is made of operators and operands. An operator is a symbol that tells the program to perform a specific action, such as + for addition or == for equality. An operand is the value or variable on which the operator acts. For example, in 7 + 2, + is the operator, and 7 and 2 are operands.

表达式由运算符和操作数组成。运算符是告诉程序执行特定操作的符号,例如 + 表示加法,== 表示相等。操作数是运算符作用的值或变量。例如,在 7 + 2 中,+ 是运算符,7 和 2 是操作数。

Operators can be classified by the number of operands they require. Unary operators act on one operand, such as the logical NOT operator or unary minus. Binary operators act on two operands, such as a + b. Most languages used in A-Level also have a ternary conditional operator, but Edexcel pseudocode tends to focus on unary and binary operators.

运算符可按所需操作数的数量分类。一元运算符作用于一个操作数,如逻辑非运算或一元负号。二元运算符作用于两个操作数,如 a + b。A-Level 中使用的大多数语言也有三元条件运算符,但 Edexcel 伪代码通常侧重一元和二元运算符。


2. Arithmetic Operators | 算术运算符

Arithmetic operators perform mathematical calculations. The core set includes + (addition), – (subtraction), * (multiplication), / (division), MOD or % (remainder), and DIV or // (integer division). In Edexcel pseudocode, MOD gives the remainder and DIV gives the quotient after integer division.

算术运算符执行数学计算。核心集合包括 +(加)、-(减)、*(乘)、/(除)、MOD 或 %(取余)以及 DIV 或 //(整除)。在 Edexcel 伪代码中,MOD 给出余数,DIV 给出整数除法后的商。

For example, 17 MOD 5 evaluates to 2 because 17 ÷ 5 = 3 remainder 2. Similarly, 17 DIV 5 evaluates to 3. The exponentiation operator is often written as ^ or **. In Python, 2 ** 3 gives 8, while in pseudocode you may see 2 ^ 3.

例如,17 MOD 5 求值为 2,因为 17 ÷ 5 = 3 余 2。类似地,17 DIV 5 求值为 3。乘方运算符通常写作 ^ 或 **。在 Python 中,2 ** 3 得到 8,而在伪代码中你可能会看到 2 ^ 3。

17 MOD 5 = 2 and 17 DIV 5 = 3

Operator Meaning Example
+ Addition 7 + 2 = 9
Subtraction 10 – 4 = 6
* Multiplication 3 * 4 = 12
/ Division 7 / 2 = 3.5
DIV or // Integer division 7 DIV 2 = 3
MOD or % Remainder 7 MOD 2 = 1
^ or ** Exponentiation 2 ^ 3 = 8

3. Relational / Comparison Operators | 关系/比较运算符

Relational operators compare two values and return a Boolean result: TRUE or FALSE. The main operators are = (equal to), <> or != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to).

关系运算符比较两个值并返回布尔结果:TRUE 或 FALSE。主要运算符有 =(等于)、<> 或 !=(不等于)、<(小于)、>(大于)、<=(小于等于)和 >=(大于等于)。

In Edexcel pseudocode, equality is often written as =, while in Python it is ==. Do not confuse = (assignment) with == (comparison). A common exam mistake is to write IF x = 5 when the intention is to compare x with 5; in many languages this assigns the value instead of testing it.

在 Edexcel 伪代码中,相等通常写作 =,而在 Python 中写作 ==。不要混淆 =(赋值)和 ==(比较)。一个常见的考试错误是当想要将 x 与 5 比较时写成 IF x = 5;在许多语言中这会赋值而不是测试。

Operator Meaning Example
= or == Equal to 5 = 5 → TRUE
<> or != Not equal to 5 <> 7 → TRUE
< Less than 3 < 4 → TRUE
更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading