There’re arithmetic and comparison operators.
Integer Arithmetic Operators | Description | Example |
+ | Addition | 1 + 2 = 3 |
- | Subtraction | 12 – 2 = 10 |
* | Multiplication | 10 * 3 = 30 |
/ | Division | 100 / 4 = 25 |
% | Modulus (Reminder) | 3 % 2 = 1 |
Comparison Operators | Description | Example | |
Returns True | Returns False | ||
< | Less than | 2 <> | 100 <> |
> | Greater than | 500 > 1 | 1 > 500 |
== | Equal to | 1 == 1 | 1 == 2 |
<= | Less than or equal | 1 <= 1 , 0.5 <= 1 | 2 <= 1 |
>= | Greater than or equal | 50 >= 50 , 100 >= 50 | 1 >= 2 |
!= | Not equal | 1 != 2 | 1 != 1 |
Other than this “=” operator known as assignment operator. It can be used within mathematical sums and also to assign values to variables.
Escape sequence
You can use escape sequences within literal strings to format text.
Escape Sequence | Description |
\b | Back Space |
\t | Tab |
\n | New Line or line feed |
\f | Form feed |
\r | Carriage return |
\” | Double quotation mark |
\’ | Single quotation mark |
\\ | Backslash |
Increment, Decrement operators
You can use operators like +, - as follows.
Ex:
++ adds one to value in variable x. And then print it (Prefix).
Ex:
Computer prints the value in x and then adds 1 to value in x (Postfix).
You can use -- same way.
Concatenation
Joining strings with other data types within a single statement is known as: Concatenation”.
Ex:
‘+’ sign is also known as “Concatenating operator”. Above example concatenate a literal string “Value in x is:” with value in x which is an integer.
No comments:
Post a Comment