Subtopic Notes

D - Operators

9-11. Data Types and Structures, Programming

Operators

  • An operator is a symbol or keyword in programming that tells the computer to perform a specific operation on one or more values (called operands)
  • May be used to compare types REAL/FLOAT and INTEGER
  • May be used to compare types CHAR and STRING
  • Case sensitive when used to compare types CHAR and/or STRING
  • Cannot be used to compare two records or object

Arithmetic operators

OperatorNameDescriptionPythonPseudocode
+ AdditionAdds together two valuesa + b a + b
- SubtractionSubtracts one value from anothera - b a - b
* MultiplicationMultiplies two valuesa * b a * b
/ DivisionDivides one value by anothera / y a / y
% ModulusReturns the division remaindera % y MOD(a, b)
**ExponentReturns a to the power of ba ** b ^
/ / Floor DivideDivide & return the whole numbera // b DIV(a, b)

Assignment operators

OperatorExamplePseudocode
=a = 5 a ← 5
<operator>=a += 5 (Represents a = a + 5)Not supported

Comparison operators

Returns a boolean value

PythonPseudocodeDescription
var == var = Equal to
var != var<> Not Equal
<, >, <=, >= <, >, <=, >=Greater/Less than (or equal to)

Logical operators

Works similar to logic gates

OperatorNamePseudocodeExample (Pseudocode)
andLogical andANDa > 9 AND a < 25
orLogical orORa > 9 OR a <25
notLogical NotNOTNOT (a = 25)

Precedence

Sets the rule on the order of operators

OperatorName
()Parentheses
**Exponent
* / // % Multiplication, Division, Floor Division, Modulus
+ -Addition, Subtraction
== != > < <= >=Comparison Operators
notLogical NOT
andLogical AND
orLogical OR