Skip to content
English

Keywords and operators

Keywords

Algorizm has 26 keywords. They cannot be used as names of variables or functions.

Keyword Meaning Python
agar if: run a block when a condition is true if
yoki agar otherwise, if another condition is true elif
aks holda otherwise else
toki repeat while a condition is true while
har … ichida go through the items of a sequence for … in
to'xta leave the loop break
davom go on with the next round of the loop continue
mayli do nothing pass
funksiya define a function def, lambda
qaytar return a value from a function return
ber hand out a value from a generator yield
global assign to a variable of the module or of an enclosing function global, nonlocal
sinf define a class class
bu the object a method was called on self
ota the parent class, inside a method super()
urin begin a block whose errors are caught try
ushla the block that runs when an error was caught except
tashla raise an error raise
import make a module available import
va and and
yoki or or
emas not not
ichida is a member of in
rost true True
yolg'on false False
bo'sh no value None

aks holda and yoki agar are each written as two words. emas ichida means "is not a member of".

Two more words are special in one place only: xossa and statik, directly before funksiya inside a class (see Classes). Everywhere else they are ordinary names.

The names of built-in functions, such as chiqar or uzunlik, are not keywords. A program may use such a word for its own variable, although the built-in function is then hidden in that place.

Operators

Operator Meaning Example Result
+ addition; joins text, lists and tuples 2 + 3 5
- subtraction; negative number 7 - 2 5
* multiplication; repeats text and lists "ab" * 2 "abab"
/ division, always a real number 7 / 2 3.5
// whole division, rounded down -7 // 2 -4
% remainder; has the sign of the divisor -7 % 2 1
** power 2 ** 10 1024
== != equal, not equal [1] == [1] rost
< <= > >= ordering of numbers, text, lists and tuples "a" < "b" rost
va and: true when both sides are true rost va yolg'on yolg'on
yoki or: true when at least one side is true rost yoki yolg'on rost
emas not emas rost yolg'on
ichida membership in text, list, tuple, set, dictionary keys, range 2 ichida [1, 2] rost
emas ichida not a member 3 emas ichida [1, 2] rost
[i] item at a position or under a key "abc"[0] "a"
[a:b] slice "abcd"[1:3] "bc"
. field, method, or member of a module "a".katta() "A"

va and yoki work out their right side only when it is needed, and return one of their two sides: ism yoki "noma'lum" gives ism unless it is empty.

Assignment is a statement, not an operator: =, and the short forms +=, -=, *= and /=. Several targets separated by commas take the items of a tuple or list: a, b = b, a.

Order of operations

Operators higher in this table are applied first. Brackets change the order.

Level Operators
1 (first) x[i], x[a:b], x.nom, f(...)
2 ** (from right to left: 2 ** 3 ** 2 is 2 ** 9)
3 -x
4 * / // %
5 + -
6 == != < <= > >= ichida emas ichida
7 emas
8 va
9 (last) yoki

Comparisons cannot be chained: write a < b va b < c.

Writing rules

  • One statement is written on one line. Inside round, square or curly brackets a statement may continue over several lines.
  • A block follows a line that ends in a colon and is indented, by four spaces as a rule.
  • A comment starts with # and runs to the end of the line.
  • Text is written in "double" or 'single' quotation marks; an f in front makes it a template with { }.
  • Numbers: 42, 1_000_000, 3.14, 1e3. There are no hexadecimal literals; use butun("ff", 16).
  • Every common apostrophe is the same letter: to'xta may be typed with ', a backtick, ʻ or ’.
  • Upper and lower case are different in names.
  • Program files are UTF-8 text with the extension .alg.