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

Operators in Programming | 编程运算符

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

📚 Operators in Programming | 编程运算符

Operators are the essential building blocks of almost every programming expression. They allow a programmer to perform calculations, compare values, combine logical conditions, and manipulate data at a low level. Understanding how operators behave, their precedence, and the differences between languages is a core part of A-Level programming and is tested frequently in Edexcel examinations.

运算符是几乎所有编程表达式的重要组成部分。它们让程序员能够执行计算、比较值、组合逻辑条件以及在底层处理数据。理解运算符的行为、优先级以及不同语言之间的差异是 A-Level 编程的核心内容,也是 Edexcel 考试中经常考查的知识点。


1. What Are Operators? | 什么是运算符?

In any programming language, an operator is a symbol or keyword that tells the computer to perform a specific operation on one or more operands. Operands can be variables, constants, literals, or more complex expressions. For example, in the expression a + b, the plus sign is the operator, while a and b are the operands.

在任何编程语言中,运算符都是一个符号或关键字,它告诉计算机对一个或多个操作数执行特定操作。操作数可以是变量、常量、字面量或更复杂的表达式。例如,在表达式 a + b 中,加号是运算符,而 a 和 b 是操作数。

Operators can be classified into several groups: arithmetic, comparison, logical, bitwise, assignment, and string operators. Each group has its own rules, and being able to classify and use operators correctly is a fundamental programming skill.

运算符可以分为几类:算术运算符、比较运算符、逻辑运算符、位运算符、赋值运算符和字符串运算符。每一类都有自己的规则,能够正确分类和使用运算符是一项基本的编程技能。


2. Arithmetic Operators | 算术运算符

n (−), multiplication (× or *), division (÷ or /), integer division (// or div), modulus (% ng on the language). In many exam questions, you will need to evaluate expressions such as 7 % 3, which returns the remainder when 7 is divided by 3, so the result is 1. Integer division gives the whole-number part of a division, for example 17 // 5 gives 3.

算术运算符用于对数值操作数执行数学计算。最常见的算术运算符有加号 (+)、减号 (−)、乘号 (× 或 *)、除号 (÷ 或 /)、整数除法 (// 或 div)、模运算 (%) 和幂运算 (** 或 ^,取决于语言)。在许多考题中,你需要计算诸如 7 % 3 这样的表达式,它返回 7 除以 3 的余数,因此结果是 1。整数除法给出除法运算的整数部分,例如 17 // 5 的结果是 3。

7 % 3 = 1   |   17 // 5 = 3

Different languages may implement division differently, especially when both operands are integers. Python always returns a float for the single slash operator (/), while languages like Java and C return an integer if both operands are integers. This is a key point for Edexcel questions that compare pseudocode with real programming languages.

不同的语言对除法的实现可能不同,尤其是当两个操作数都是整数时。Python 的单斜杠运算符 (/) 总是返回浮点数,而 Java 和 C 等语言在两个操作数都是整数时返回整数。这是 Edexcel 题目中比较伪代码与真实编程语言时的一个关键点。


3. Comparison Operators | 比较运算符

comparison operators include equal to (= or == depending on language), not equal to (≠ or ! than or equal to (≤ or &lt;=), and greater than or equal to (≥ or &gt;=). For example, if x = 5 and y = 10, then x < y evaluates to true, while x == y evaluates to false.

比较运算符(也称为关系运算符)比较两个值并返回布尔结果:真或假。常见的比较运算符包括等于 (= 或 ==,取决于语言)、不等于 (≠ 或 !=)、小于 (<)、大于 (>)、小于或等于 (≤ 或 &lt;=) 以及大于或等于 (≥ 或 &gt;=)。例如,如果 x = 5 且 y = 10,那么 x < y 的结果为真,而 x == y 的结果为假。

arison. This distinction is a frequent source of errors, especially for beginners and in trace table questions. Always check whether a statement is assigning a value or testing equality.

在编程中,单个等号通常表示赋值,而双等号 (==) 用于比较。这一区别是常见的错误来源,尤其是对于初学者和在跟踪表题目中。始终要检查一条语句是在赋值还是在测试相等性。


4. Logical Operators | 逻辑运算符

Logical operators combine Boolean expressions and produce a Boolean result. The three fundamental logical operators are AND, OR, and NOT. In many languages, AND is represented as && or and, OR as || or or, and NOT as ! or not. The AND operator returns true only if both operands are true. The OR operator returns true if at least one operand is true. The NOT operator reverses the Boolean value of its operand, so NOT true is false.

逻辑运算符组合布尔表达式并产生布尔结果。三个基本逻辑运算符是 AND、OR 和 NOT。在许多语言中,AND 表示为 && 或 and,OR 表示为 || 或 or,NOT 表示为 ! 或 not。AND 运算符只有在两个操作数都为真时才返回真。OR 运算符在至少一个操作数为真时返回真。NOT 运算符反转其操作数的布尔值,因此 NOT true 为 false。

Truth tables are an essential tool for understanding logical operators. For instance, if p is true and q is false, then p AND q is false, p OR q is true, and NOT p is false. In exam questions, you may be asked to construct a truth table for a compound condition.

真值表是理解逻辑运算符的重要工具。例如,如果 p 为真且 q 为假,那么 p AND q 为假,p OR q 为真,而 NOT p 为假。在考试题中,你可能会被要求为一个复合条件构造真值表。


广告 / Sponsored

5. Bitwise Operators | 位运算符

ers, treating each bit separately. The most common bitwise operators are AND (&), OR (|), XOR (^), NOT (~ mal. Bitwise shifts multiply or divide by powers of two: shifting left by 1 bit doubles an integer, while shifting right by 1 bit halves it using integer division.

位运算符对整数的二进制表示进行运算,逐位分别处理。最常见的位运算符是 AND (&)、OR (|)、XOR (^)、NOT (~)、左移 (<<) 和右移 (>>)。例如,12(二进制 1100)和 10(二进制 1010)的按位 AND 结果是 1000,即十进制的 8。按位移位可以乘以或除以 2 的幂:左移 1 位使整数加倍,而右移 1 位使整数减半(使用整数除法)。

12 & 10 = 8   |   1100 & 1010 = 1000

These operators are often tested in Edexcel A-Level questions about low-level programming and efficiency. They are also useful for tasks such as setting or clearing specific bits in a binary flag system.

这些运算符在 Edexcel A-Level 关于低级编程和效率的问题中经常被考查。它们对于在二进制标志系统中设置或清除特定位等任务也非常有用。


6. Assignment Operators | 赋值运算符

languages, the assignment operator is a single equals sign (=). For example, the statement total = price + tax calculates the expression on the right-hand side and stores the result in the variable total. It is important to remember that assignment is not an equation: the left-hand side must be a variable, and the process is directional (right to left).

赋值运算符用于将值存储到变量中。在大多数语言中,赋值运算符是一个等号 (=)。例如,语句 total = price + tax 计算右侧的表达式并将结果存储在变量 total 中。重要的是要记住,赋值不是等式:左侧必须是一个变量,而且过程是有方向的(从右到左)。

Some languages also support multiple assignment or chained assignment, such as a = b = c = 0. In pseudocode, the assignment operator is often written as a left arrow (←) to make the direction clearer, but Edexcel papers usually accept an equals sign when using common coding practice.

一些语言还支持多重赋值或链式赋值,例如 a = b = c = 0。在伪代码中,赋值运算符通常写成左箭头 (←) 以使方向更清晰,但 Edexcel 试卷在使用常见编码实践时通常接受等号。


7. Compound Assignment Operators | 复合赋值运算符

n with assignment, making code shorter and often clearer. Examples include +=, −=, *=, /=, %=, &amp;=, |=, and ^=. The expression x += 5 is equivalent to x = x + 5. Similarly, y *= 2 means y = y * 2.

复合赋值运算符将算术或位运算与赋值结合起来,使代码更简短且通常

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

广告 / Sponsored
2027中央戏剧学院612戏剧基础801戏剧影视表演理论考研初试一本通真题笔记知识重点总结技巧题库学复习资料教材模拟卷
戏剧 备考教辅 · 正版现货 · 学习备考通用
查看详情 / View on Taobao参考价 ¥6.8
广告 / Sponsored
英文原版 The Cambridge Companion to the Beatles 剑桥披头士乐队研究指南 剑桥音…
音乐 备考教辅 · 正版现货 · 学习备考通用
查看详情 / View on Taobao参考价 ¥261.0

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

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