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

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

Operators and expressions are fundamental to writing correct programs in any language. In Edexcel A-Level Computer Science, candidates must be able to use arithmetic, relational, Boolean and assignment operators confidently, and must understand how precedence rules determine the order of evaluation. This article explains each operator category with clear examples, common pitfalls, and exam-style tips.

运算符和表达式是编写正确程序的基础。在 Edexcel A-Level 计算机科学课程中,考生必须能够自信地使用算术运算符、关系运算符、布尔运算符和赋值运算符,并理解优先级规则如何决定求值顺序。本文通过清晰的示例、常见误区和考试技巧逐一讲解各类运算符。


1. Arithmetic Operators | 算术运算符

Arithmetic operators perform mathematical calculations on numeric values. The standard operators include addition (+), subtraction (-), multiplication (*), division (/), integer division (// or DIV), modulo (%), and exponentiation (** or ^ depending on the language).

算术运算符对数值执行数学计算。标准运算符包括加(+)、减(-)、乘(*)、除(/)、整除(// 或 DIV)、取模(%)和幂运算(** 或 ^,取决于语言)。

In Python, the expression 7 + 3 * 2 evaluates to 13 because multiplication has higher precedence than addition. The expression (7 + 3) * 2 evaluates to 20, showing how parentheses change the order of calculation.

在 Python 中,表达式 7 + 3 * 2 的值为 13,因为乘法的优先级高于加法。表达式 (7 + 3) * 2 的值为 20,说明括号如何改变运算顺序。

  • Use * for multiplication and / for real division. | 乘法用 *,实数除法用 /。
  • Use // for integer floor division, e.g. 17 // 5 = 3. | 整数向下取整除法用 //,例如 17 // 5 = 3。
  • Use % for remainder, e.g. 17 % 5 = 2. | 取余用 %,例如 17 % 5 = 2。

a + b × c ≠ (a + b) × c

Many exam questions expect you to trace arithmetic expressions step by step. Always write down intermediate results to avoid careless

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

更多咨询请联系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

Exit mobile version