Edexcel A Level Programming Operators | Edexcel A Level 编程运算符

📚 Edexcel A Level Programming Operators | Edexcel A Level 编程运算符

Operators are the building blocks of expressions in programming. They act on one or more values called operands to produce a new value or a Boolean result. In the Edexcel A Level Computer Science specification, you need to understand arithmetic, comparison, Boolean and bitwise operators, and to use them correctly in pseudocode, Python, Java or any other taught language.

运算符是程序中表达式的基本构件。它们作用于一个或多个称为操作数的值,以产生新值或布尔结果。在 Edexcel A Level 计算机科学考试大纲中,你需要理解算术、比较、布尔和位运算符,并在伪代码、Python、Java 或任何其他教学语言中正确使用它们。

1. Operator Categories | 运算符分类

An operator is classified by the number of operands it takes. A unary operator acts on one operand, a binary operator acts on two, and a ternary operator acts on three. Most operators in Edexcel programming are binary; examples include +, -, *, /, AND and OR. Unary examples include NOT and the negative sign.

运算符按其操作数数量分类。一元运算符作用于一个操作数,二元运算符作用于两个操作数,三元运算符作用于三个操作数。Edexcel 编程中的大多数运算符是二元的,例如 +、-、*、/、AND 和 OR。一元示例包括 NOT 和负号。

You should be able to identify the operator and operands in an expression such as x + y, where + is the operator and x and y are operands. The result depends on the data types: arithmetic operators usually return numeric values, while comparison and Boolean operators return TRUE or FALSE.

你应该能够在表达式(如 x + y)中识别运算符和操作数,其中 + 是运算符,x 和 y 是操作数。结果取决于数据类型:算术运算符通常返回数值,而比较和布尔运算符返回 TRUE 或 FALSE。

Category Example operators Typical result
Arithmetic | 算术 + – * / DIV MOD ^ Numeric value
Comparison | 比较 = ≠ < > ≤ ≥ TRUE or FALSE
Boolean | 布尔 AND OR NOT TRUE or FALSE
Bitwise | 位 AND OR XOR NOT << >> Binary integer

2. Arithmetic Operators | 算术运算符

Arithmetic operators are used in calculations. Edexcel pseudocode uses + for addition, – for subtraction, * for multiplication, / for real division, DIV for integer division, MOD for remainder and ^ for exponentiation. The distinction between / and DIV is important: DIV discards the fractional part and returns an integer, while / keeps the decimal result.

算术运算符用于计算。Edexcel 伪代码使用 + 表示加法、- 表示减法、* 表示乘法、/ 表示实数除法、DIV 表示整数除法、MOD 表示余数、^ 表示乘方。/ 与 DIV 的区别很重要:DIV 丢弃小数部分并返回整数,而 / 保留小数结果。

Operator Meaning Example Result
+ Addition | 加法 7 + 2 9
– Subtraction | 减法 7 – 2 5
* Multiplication | 乘法 7 * 2 14
/ Real division | 实数除法 7 / 2 3.5
DIV Integer division | 整数除法 7 DIV 2 3
MOD Remainder | 余数 7 MOD 2 1
^ Exponentiation | 乘方 2 ^ 3 8

In many programming languages, integer division is written as // in Python or / in Java when both operands are integers, while remainder is % in Python and Java. Always check the exact notation required by the question, but in Edexcel pseudocode use DIV and MOD.

在许多编程语言中,整数除法在 Python 中写作 //,在 Java 中当两个操作数都是整数时写作 /,而求余在 Python 和 Java 中写作 %。一定要根据题目要求检查具体写法,但在 Edexcel 伪代码中使用 DIV 和 MOD。


3. Assignment and Compound Assignment | 赋值与复合赋值运算符

Assignment stores a value in a variable. Edexcel pseudocode often uses =, but in this article we write ← so that assignment is not confused with equality. For example, x ← x + 1 means ‘take the current value of x, add 1, and store the result back in x’.

赋值将值存储在变量中。Edexcel 伪代码通常使用 =,但本文中使用 ←,以免赋值与相等比较混淆。例如,x ← x + 1 的意思是 ‘取 x 的当前值,加 1,并将结果存回 x’。

Many high-level languages provide compound assignment shortcuts such as x += 1, x -= 1, x *= 2 and x /= 2. These are equivalent to x ← x + 1 and so on. They are not a separate mathematical operation, just a shorter way of writing an update.

许多高级语言提供复合赋值简写,例如 x += 1、x -= 1、x *= 2 和 x /= 2。它们分别等价于 x ← x + 1 等。它们并不是独立的数学运算,只是更新变量的一种更简短写法。

  • In Python: count += 1 is the same as count = count + 1.
  • In Java: total *= 2 is the same as total = total * 2.

在 Python 中:count += 1 与 count = count + 1 相同。

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

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

📞 咨询 / 微信:16621398022(同微信)
A-Level / IGCSE / IB / AP 课程辅导 · 真题资料 · 留学申请规划
查看联系方式 →

Comments

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

Turn on JavaScript to leave a comment.

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

咨询微信:16621398022(同微信) · 联系我们
Exit mobile version