Skip to content

Operators

Pranav Verma edited this page Dec 3, 2024 · 4 revisions

Mathematical Operators

Addition (+)

Addition Can Be Performed On Integers, and Floats. If Using Addition Between two Strings, it will Concatenate them.

var a = 1;
var b = 2;
var c = (a + b);

print(a + b);
var a = "hello";
var b = "hi";

print(a + b);

Multiplication (*)

Multiplication is Used in Integers, and Floats.
You can also multiply a string by a integer to duplicate it, but, if multiplying a string by a string, it will throw an error.

var a = 10;
var b = 20;

print(a * b);
var a = "hello";
var b = (a * 3);

print(b);

Division (/)

Division is used between Integers and Floats.
Returns float as a Data Type.

var a = 10;
var b = 20;

print(a / b);

Floor Division (//)

Floor Division is used between Integers and Floats. Always Returns int as the Data Type.
Ignores Everything After the Decimal Point.

var a = 10;
var b = 20;

print(a // b);

Power (**)

Power is used between Integers and Floats.

var a = 10;
var b = 2;

print(a ** b);

Modulus Remainder (%)

Modulus is used between Integers and Floats. It Returns the Remainder after Dividing Two Numbers.

var a = 10;
var b = 2;

print(a % b);

Comparison Operators

  • == (is equal to)
  • >= (greater than or equal to)
  • <= (less than or equal to)
  • > (greater than)
  • < (less than)
  • != (not equal to)

Unary / Assignment Operators

  • + (plus)
  • - (minus)
  • ! (not)
  • = (set / assign)

Slicing

Slicing allows you to extract parts of arrays or strings using the syntax: array[start:stop:step]

  • start: Starting index (optional, defaults to 0 for positive step, or length-1 for negative step)
  • stop: Ending index (optional, defaults to length for positive step, or -1 for negative step)
  • step: Step size (optional, defaults to 1)

All indices support negative numbers to count from the end of the sequence.

Examples:

Clone this wiki locally