Documentation topicsOperators
Lexical Structure
Control Flow
Functions & Scope
Lists & Built-ins
Reference
MarathiCode v0.2.0
Operators
अंकगणितीय, तुलना व तार्किक ऑपरेटर
Arithmetic
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | Addition; joins strings; joins two lists | 10 + 5 | 15 |
| - | Subtraction; unary minus | 10 - 15 | -5 |
| * | Multiplication | 4 * 2.5 | 10 |
| / | Division (always true division) | 7 / 2 | 3.5 |
| % | Remainder (sign follows the left side) | -7 % 3 | -1 |
-, *, / and % work on numbers only. + adds two numbers, joins two lists, or, when either side is a string, joins text. Any other combination is a runtime error.
Comparison
| Operator | Meaning | Example | Result |
|---|---|---|---|
| == | Equal | 2 + 2 == 4 | खरे |
| != | Not equal | "अ" != "ब" | खरे |
| > | Greater than | 10 > 5 | खरे |
| < | Less than | 10 < 5 | खोटे |
| >= | Greater than or equal | 5 >= 5 | खरे |
| <= | Less than or equal | 4 <= 3 | खोटे |
==and!=work on any values. Values of different kinds are never equal, and lists are compared element by element.>,<,>=,<=need two numbers or two strings.
Logical
| Operator | Meaning |
|---|---|
| आणि | AND: true when both sides are true |
| किंवा | OR: true when at least one side is true |
| नाही | NOT: reverses a value (unary) |
आणि and किंवा are short-circuit operators: the right side is evaluated only when the left side does not already decide the result. They return the deciding value itself.
short_circuit.mr
कार्य तपासा() {
छापा("उजवी बाजू तपासली")
परत खरे
}
छापा(खोटे आणि तपासा())
छापा(खरे किंवा तपासा())
छापा(खरे आणि तपासा())
छापा(0 किंवा "पर्याय")Output (आउटपुट)
खोटे खरे उजवी बाजू तपासली खरे पर्याय
Short-circuiting also lets a condition guard the expression after it:
guard.mr
चल यादी = []
जर लांबी(यादी) > 0 आणि यादी[0] == 5 तर {
छापा("पहिली संख्या 5")
} नाहीतर {
छापा("तपासले नाही")
}Output (आउटपुट)
तपासले नाही
The order in which operators apply is described in Operator Precedence.