← 返回资讯屏轩教育 · 行业资讯

A-Level Programming Operators: Arithmetic, Comparison and Boolean Logic | A-Level 编程运算符:算术、比较与布尔逻辑

2026-08-29 15:29 · 本文部分内容由AI辅助创作

📚 A-Level Programming Operators: Arithmetic, Comparison and Boolean Logic | A-Level 编程运算符:算术、比较与布尔逻辑

In Edexcel A-Level Computer Science, operators are symbols or keywords that instruct a program to perform specific operations on one or more operands. A solid understanding of arithmetic, comparison, Boolean and assignment operators is essential for writing correct algorithms, controlling selection and iteration, and manipulating data in both pseudocode and high-level languages such as Python.

在 Edexcel A-Level 计算机科学中,运算符是指示程序对一个或多个操作数执行特定操作的符号或关键字。扎实掌握算术、比较、布尔和赋值运算符,对于编写正确的算法、控制选择与循环结构,以及在伪代码和 Python 等高级语言中处理数据都至关重要。


1. What Are Operators and Why They Matter | 什么是运算符及其重要性

An operator works by taking one or more values, called operands, and producing a new value. For example, in the expression 6 + 2, the plus sign is the operator, while 6 and 2 are the operands. Operators can be unary, meaning they act on a single operand, or binary, meaning they act on two operands. Edexcel exam questions frequently require you to evaluate expressions, predict outputs, or correct code that uses the wrong operator.

运算符通过接收一个或多个值(称为操作数)并产生新值来工作。例如,在表达式 6 + 2 中,加号是运算符,而 6 和 2 是操作数。运算符可以是一元运算符(只作用于一个操作数),也可以是二元运算符(作用于两个操作数)。Edexcel 考试题目经常要求你求表达式的值、预测输出,或者更正使用错误运算符的代码。

The main categories you need to know are arithmetic, assignment, comparison, Boolean, bitwise and string operators. Each category has a clear role in building logical conditions, updating variables and performing calculations. Understanding which data types can be used with each operator is also vital, because applying an operator to an incompatible type will cause a runtime error.

你需要掌握的主要类别包括算术、赋值、比较、布尔、位和字符串运算符。每一类运算符在构建逻辑条件、更新变量和执行计算时都有明确的作用。理解每种运算符可以用于哪些数据类型也非常重要,因为将运算符应用于不兼容的类型会导致运行时错误。


2. Arithmetic Operators: Core Calculations | 算术运算符:核心计算

Arithmetic operators perform mathematical calculations on numeric operands. The standard operators in Edexcel pseudocode and Python include addition, subtraction, multiplication, division, integer division, modulus and exponentiation. The table below summarises their typical symbols and examples.

算术运算符对数值操作数执行数学计算。Edexcel 伪代码和 Python 中的标准算术运算符包括加法、减法、乘法、除法、整除、取余(模)和幂运算。下表总结了它们的典型符号和示例。

OperatorNameExampleResult
+Addition6 + 28
-Subtraction6 - 24
*Multiplication6 * 212
/Division7 / 23.5
DIV or //Integer division7 DIV 23
MOD or %Modulus (remainder)7 MOD 21
^ or **Exponentiation238

Note that the division operator / may produce a real (float) result even if both operands are integers. Integer division DIV or // discards the fractional part, always returning a whole number. In most languages, the unary minus operator also changes the sign of a numeric value.

请注意,即使两个操作数都是整数,除法运算符 / 也可能产生实数(浮点数)结果。整除运算符 DIV 或 // 会舍弃小数部分,始终返回整数。在大多数语言中,一元负号运算符还会改变数值的符号。


3. Integer Division and Modulus in Pseudocode | 伪代码中的整除与取余

For example, 17 DIV 5 equals 3, and 17 MOD 5 equals 2 because 3 × 5 = 15 and 17 - 15 = 2.

整除和取余在 Edexcel 试卷中出现频率很高,因为它们可以用于提取数字、测试整除性以及控制循环。整除返回一个数完整包含另一个数的次数,而取余返回整除后的余数。例如,17 DIV 5 等于 3,17 MOD 5 等于 2,因为 3 × 5 = 15,而 17 - 15 = 2。

0 then n is even; otherwise n is odd. Another use is digit extraction: to get the last digit of a number, calculate n MOD 10. To remove the last digit, calculate n DIV 10. You can repeat this process to reverse an integer or sum its digits.

取余运算的一个常见用途是检查一个数是偶数还是奇数。如果 n MOD 2 = 0,则 n 为偶数;否则 n 为奇数。另一个用途是提取数字:要获得一个数的最后一位,可以计算 n MOD 10;要删除最后一位,可以计算 n DIV 10。你可以重复这个过程来反转一个整数或对其各位数字求和。


4. Assignment Operators and Shorthand Notation | 赋值运算符与简写符号

An assignment operator stores a value in a variable. In Edexcel pseudocode, the left arrow ← is often used, as in total ← signment. It is crucial not to confuse assignment with equality: assignment changes a variable, whereas equality compares two values.

赋值运算符用于将值存储到变量中。在 Edexcel 伪代码中,通常使用左箭头 ←,例如 total ← total + 1。在 Python 和许多其他语言中,等号 = 执行赋值操作。关键是要区分赋值与相等:赋值会修改变量,而相等比较的是两个值。

erators provide a shorter way to update a variable. For example, x += 5 is equivalent to x ← x + 5. The table below shows common shorthand forms and their long equivalents.

复合赋值运算符提供了一种更简洁的变量更新方式。例如,x += 5 等价于 x ← x + 5。下表展示了常见的简写形式及其等价的长写法。

ShorthandEquivalent
x += 5x ← x + 5
x -= 5x ← x - 5
x *= 5x ← x * 5
x /= 5x ← x / 5

some pseudocode conventions, assignment is written as =, while in others it is written as ← is evaluated first, and then the resulting value is stored into the variable on the left.

在某些伪代码约定中,赋值写作 =,而在另一些中写作 ←。你必须熟悉这两种写法,以免在考试中读错题。关键思想是:先计算右侧表达式的值,然后将结果存储到左侧的变量中。


5. Comparison Operators: Making Decisions | 比较运算符:做出判断

Comparison operators compare two values and return a Boolean result, either TRUE or FALSE. They are used mainly in IF statements, WHILE loops and REPEAT loops to control the flow of a program. The most common comparison operators are equal to, not equal to, less than, greater than, less than or equal to and greater than or equal to.

比较运算符用于比较两个值,并返回布尔结果:TRUE 或 FALSE。它们主要用在 IF 语句、WHILE 循环和 REPEAT 循环中,以控制程序的流程。最常见的比较运算符包括等于、不等于、小于、大于、小于或等于以及大于或等于。

OperatorMeaningExampleResult
= or ==Equal to5 = 5TRUE
≠ or !=Not equal to5 ≠ 3TRUE
<Less than3 < 8TRUE
>Greater than3 > 8FALSE
≤ or &lt;=Less than or equal to4 ≤ 4TRUE
≥ or &gt;=Greater than or equal to4 ≥ 6FALSE

e, = may be used for both assignment and equality, so you must always examine the context.

一个非常常见的考试错误是在需要 == 进行相等比较的语言中使用单个等号 =。在 Python 中,在条件中使用 = 会导致语法错误,因为 = 被保留用于赋值。在 Edexcel 伪代码中,= 可能同时用于赋值和相等比较,因此你必须始终根据上下文来判断。


广告 / Sponsored

6. Boolean Operators: AND, OR, NOT | 布尔运算符:与、或、非

Boolean operators combine or invert Boolean values. The three fundamental Boolean operators are AND, OR and NOT. They are essential for constructing complex conditions, such as checking whether a number is within a range or whether a username and password are both correct.

布尔运算符用于组合或反转布尔值。三种基本的布尔运算符是 AND、OR 和 NOT。它们对于构造复杂条件至关重要,例如检查一个数是否在某个范围内,或者用户名和密码是否都正确。

AND returns TRUE only when both operands are TRUE. OR returns TRUE when at least one operand is TRUE. NOT is a unary operator that reverses the Boolean value: NOT TRUE becomes FALSE, and NOT FALSE becomes TRUE. The truth table below shows all possible outcomes.

AND 仅当两个操作数都为 TRUE 时才返回 TRUE。OR 只要至少一个操作数为 TRUE 就返回 TRUE。NOT 是一元运算符,会反转布尔值:NOT TRUE 变为 FALSE,NOT FALSE 变为 TRUE。下面的真值表展示了所有可能的结果。

ABA AND BA OR BNOT A
TRUETRUETRUETRUEFALSE
TRUEFALSEFALSETRUEFALSE
FALSETRUEFALSETRUETRUE
FALSEFALSEFALSEFALSETRUE

In many languages, AND is written as &&, OR as || and NOT as !. However, in Edexcel pseudocode and Python you will typically see the keywords AND, OR and NOT. You must be able to simplify complex Boolean expressions and construct correct test conditions from a written specification.

在许多语言中,AND 写作 &&,OR 写作 ||,NOT 写作 !。然而,在 Edexcel 伪代码和 Python 中,你通常看到的是关键字 AND、OR 和 NOT。你必须能够化简复杂的布尔表达式,并根据书面规范构造正确的测试条件。


7. Bitwise Operators: Low-Level Manipulation | 位运算符:底层操作

Bitwise operators act on the individual bits of integer values. They are less common in high-level algorithm questions but still appear in Edexcel Computer Science when discussing low-level data representation and binary arithmetic. The main bitwise operators are bitwise AND, bitwise OR, bitwise XOR and bitwise NOT.

位运算符作用于整数值的各个二进制位。它们在高级算法题中较少出现,但在讨论底层数据表示和二进制算术时,Edexcel 计算机科学中仍会出现。主要的位运算符包括按位与、按位或、按位异或和按位非。

For example, 12 in binary is 1100 and 10 is 1010. The bitwise AND gives 1000 (8), the bitwise OR gives 1110 (14), and the bitwise XOR gives 0110 (6). A left shift operation moves all bits one place to the left, effectively multiplying by 2, while a right shift divides by 2 and discards the remainder.

例如,12 的二进制是 1100,10 的二进制是 1010。按位与得到 1000(8),按位或得到 1110(14),按位异或得到 0110(6)。左移操作将所有位向左移动一位,相当于乘以 2;右移操作则相当于除以 2 并舍去余数。

Although Edexcel pseudocode often focuses on high-level operations, understanding that integers are stored as binary and that bit shifts can perform fast multiplication and division is valuable. It also connects programming operators with the data representation topic in the specification.

尽管 Edexcel 伪代码通常关注高级操作,但理解整数以二进制存储、位移可以执行快速的乘法和除法是非常有价值的。这还将编程运算符与考试大纲中的数据表示主题联系起来。


8. Operator Precedence: Order of Evaluation | 运算符优先级:求值顺序

When an expression contains multiple operators, precedence rules determine the order in which the operations are carried out. In most programming languages, the order from highest to lowest priority is: parentheses, exponentiation, unary minus, multiplication and division, addition and subtraction, comparison operators, NOT, AND, and finally OR.

当一个表达式包含多个运算符时,优先级规则决定了运算的执行顺序。在大多数编程语言中,从高到低的优先级顺序为:括号、幂运算、一元负号、乘法和除法、加法和减法、比较运算符、NOT、AND,最后是 OR。

Priority: ( ) → ^ or ** → unary - → * / DIV MOD → + - → < > ≤ ≥ = ≠ → NOT → AND → OR

For example, in the expression 3 + 4 * 2, multiplication happens first, so the result is 11, not 14. If you want addition to happen first, you must use parentheses: (3 + 4) * 2 equals 14. Exam questions often test your ability to add brackets or evaluate a given expression according to precedence rules.

例如,在表达式 3 + 4 * 2 中,乘法先发生,因此结果是 11,而不是 14。如果你希望加法先发生,就必须使用括号:(3 + 4) * 2 等于 14。考试题目经常测试你是否能根据优先级规则添加括号或求给定表达式的值。

Always remember that brackets have the highest priority, so if you are unsure, add extra parentheses to make your intention clear. In code, clear parentheses improve readability and prevent logical errors, even if the language would evaluate the expression correctly without them.

请始终记住,括号的优先级最高,所以如果不确定,就添加额外的括号来明确你的意图。在代码中,清晰的括号可以提高可读性并防止逻辑错误,即使语言本身在无括号时也能正确求值。


9. String Concatenation and Repetition Operators | 字符串连接与重复运算符

Operators are not only for numbers. In many programming languages, the plus sign + is also used to concatenate strings, joining them end to end. For example, "Hello" + "World" produces "HelloWorld". Some languages, such as Python, also support the multiplication operator * to repeat a string: "Hi" * 3 produces "HiHiHi".

运算符不仅仅用于数字。在许多编程语言中,加号 + 也用于连接字符串,将它们首尾相连。例如,"Hello" + "World" 会生成 "HelloWorld"。一些语言(如 Python)还支持乘法运算符 * 来重复

Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

广告 / Sponsored
2026秋实验班提优大考卷七八年级上下册九年级语文数学英语物理化学人教版初中教材考试卷沪科版浙教版外研版科学译林版新版…
化学、物理 备考教辅 · 正版现货 · 学习备考通用
查看详情 / View on Taobao
广告 / Sponsored
DK Rapping Up Biology Physics Chemistry 说唱生物 物理 化学 趣味复习指南 G…
物理、化学 备考教辅 · 正版现货 · 学习备考通用
查看详情 / View on Taobao

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao