Standard library
The standard library is built into the algorizm program; nothing has to be installed. A module is made available with import and used through its name: matematika.ildiz(16).
Module
Python
Purpose
matematika
math
mathematical functions and constants
tasodif
random
random numbers
vaqt
time
the clock and waiting
sana
datetime
calendar dates
fayl
open, os, shutil
reading and writing files
papka
os, os.path
folders and paths
tizim
sys, os
the program and its surroundings
json
json
the JSON data format
qolip
re
regular expressions
matematika#
Name
Meaning
PI, E
the constants π and e
ildiz(x)
square root
daraja(x, y)
x to the power y; the result is always a real number
sin(x), cos(x), tan(x)
sine, cosine and tangent of an angle in radians
log(x[, asos])
logarithm to the given base; without a base, the natural logarithm
pastga(x)
rounds down to a whole number
yuqoriga(x)
rounds up to a whole number
import matematika
chiqar (matematika.PI, matematika.E)
chiqar (matematika.ildiz(2 ), matematika.daraja(2 , 0.5 ))
chiqar (matematika.sin(0 ), matematika.cos(0 ), matematika.log(100 , 10 ))
chiqar (matematika.pastga(-3.5 ), matematika.yuqoriga(-3.5 ))Output
3.1415926535897931 2.7182818284590451
1.4142135623730951 1.4142135623730951
0.0 1.0 2.0
-4 -3
tasodif#
Name
Meaning
son()
a random real number, at least 0 and less than 1
butun(a, b)
a random whole number from a to b, both included
tanla(royxat)
a random item of a list
aralashtir(royxat)
puts the items of a list into random order, changing the list itself
import tasodif
chiqar (tasodif.son())
chiqar (tasodif.butun(1 , 6 ))
chiqar (tasodif.tanla(["olma" , "anor" , "uzum" ]))
kartalar = [1 , 2 , 3 , 4 , 5 ]
tasodif.aralashtir(kartalar)
chiqar (kartalar)
The results differ at every run, so no output is shown here.
vaqt#
Name
Meaning
hozir()
the current time as seconds since the beginning of 1970, with fractions
kut(soniya)
pauses the program for this many seconds
Subtracting two values of hozir() measures how long something took:
import vaqt
boshi = vaqt.hozir()
vaqt.kut(0.2 )
chiqar (yaxlitla (vaqt.hozir() - boshi, 1 ))
sana#
sana works with calendar dates in local time. A moment is the same number of seconds that vaqt.hozir() returns, so moments can be compared, subtracted and added to.
Name
Meaning
hozir()
the current date and time as a dictionary with the keys yil, oy, kun, soat, daqiqa, soniya
qismlar(soniya)
the same dictionary for a given moment
yasa(yil, oy, kun[, soat, daqiqa, soniya])
the moment for a date, as seconds since 1970
formatla(soniya, andoza)
a moment as text, following a pattern
hafta_kuni(soniya)
the Uzbek name of the weekday: "dushanba" … "yakshanba"
oy_nomi(oy)
the Uzbek name of a month: "yanvar" … "dekabr"
import sana
t = sana.yasa(2026 , 11 , 25 , 14 , 3 )
chiqar (sana.formatla(t, "%d.%m.%Y %H:%M" ))
chiqar (sana.hafta_kuni(t), sana.oy_nomi(11 ))
chiqar (sana.formatla(t, "%A, %d-%B %Y" ))
q = sana.qismlar(t)
chiqar (q["yil" ], q["oy" ], q["kun" ], q["soat" ], q["daqiqa" ])
ertaga = t + 24 * 60 * 60
chiqar (sana.formatla(ertaga, "%d.%m.%Y" ))Output
25.11.2026 14:03
chorshanba noyabr
chorshanba, 25-noyabr 2026
2026 11 25 14 3
26.11.2026
In a pattern for formatla, these codes are replaced:
Code
Meaning
Example
%Y
year
2026
%y
year, two digits
26
%m
month, two digits
11
%d
day, two digits
25
%H
hour, 00 to 23
14
%M
minute
03
%S
second
00
%A
name of the weekday
chorshanba
%B
name of the month
noyabr
%%
a percent sign
%
fayl#
Name
Meaning
o'qi(yo'l)
the whole file as text
qatorlar(yo'l)
the lines of the file as a list
yoz(yo'l, matn)
writes text to a file; an existing file is replaced
qo'sh(yo'l, matn)
adds text to the end of a file
bormi(yo'l)
does the file exist
o'chir(yo'l)
deletes the file
nomla(eski, yangi)
renames or moves a file; an error if the new name is taken
nusxa(qayerdan, qayerga)
copies a file
hajm(yo'l)
the size of the file in bytes
o'qi_bayt(yo'l)
the whole file as baytlar, for images and other files that are not text
yoz_bayt(yo'l, baytlar)
writes bytes to a file; an existing file is replaced
qo'sh_bayt(yo'l, baytlar)
adds bytes to the end of a file
import fayl
fayl.yoz("baholar.txt" , "Ali 5\nVali 4\n" )
fayl.qo'sh("baholar.txt" , "Guli 5\n" )
har qator ichida fayl.qatorlar("baholar.txt" ):
ism, baho = qator.ajrat()
chiqar (ism, butun (baho))
chiqar (fayl.bormi("baholar.txt" ), fayl.hajm("baholar.txt" ))
fayl.nusxa("baholar.txt" , "zaxira.txt" )
fayl.nomla("zaxira.txt" , "eski.txt" )
fayl.o'chir("baholar.txt" )
fayl.o'chir("eski.txt" )
chiqar (fayl.bormi("baholar.txt" ))Output
Ali 5
Vali 4
Guli 5
rost 20
yolg'on
Text files are UTF-8. Windows line ends are read as \n.
A relative path starts from the folder in which the command was run, not from the folder of the program file.
yoz replaces an existing file and o'chir deletes for good. Neither asks first.
fayl reads and writes whole files; there is no reading piece by piece.
A file that is missing or cannot be opened is an error that urin can catch:
import fayl
urin :
mazmun = fayl.o'qi("yoq_fayl.txt" )
ushla xato:
chiqar (xato)Output
fayl.o'qi: 'yoq_fayl.txt' faylini ochib bo'lmadi (fayl topilmadi)
papka#
Name
Meaning
ro'yxat(yo'l)
sorted list of the names inside a folder
yarat(yo'l)
creates a folder, together with any missing parent folders
o'chir(yo'l)
deletes an empty folder
bormi(yo'l)
does the folder exist
joriy()
the path of the current folder
birlashtir(a, b, ...)
joins the parts of a path with /
nom(yo'l)
the last part of a path: "a/b/c.txt" gives "c.txt"
ota(yo'l)
everything before the last part: "a/b/c.txt" gives "a/b"
kengaytma(yo'l)
the extension of a file name: ".txt"
import papka
import fayl
papka.yarat("hisobotlar/2026" )
fayl.yoz("hisobotlar/2026/yanvar.txt" , "..." )
chiqar (papka.ro'yxat("hisobotlar" ), papka.ro'yxat("hisobotlar/2026" ))
yol = papka.birlashtir("hisobotlar" , "2026" , "yanvar.txt" )
chiqar (yol)
chiqar (papka.nom(yol), papka.ota(yol), papka.kengaytma(yol))
fayl.o'chir(yol)
papka.o'chir("hisobotlar/2026" )
papka.o'chir("hisobotlar" )
chiqar (papka.bormi("hisobotlar" ))Output
["2026"] ["yanvar.txt"]
hisobotlar/2026/yanvar.txt
yanvar.txt hisobotlar/2026 .txt
yolg'on
Paths may be written with / on every system, including Windows.
tizim#
Name
Meaning
argumentlar
list of the words that followed the program's name on the command line
platforma
"windows", "linux" or "macos"
versiya
the version of Algorizm as text
chiqish([kod])
stops the program at once; kod is the exit code given to the system, 0 if left out
muhit(nom)
the value of an environment variable, or bo'sh if it is not set
import tizim
chiqar (tizim.argumentlar)
chiqar (tizim.versiya, tizim.muhit("YOQ_OZGARUVCHI" ))
Run as algorizm dastur.alg bir ikki, the program sees tizim.argumentlar == ["bir", "ikki"].
json#
JSON is a text format for exchanging data between programs.
Name
Meaning
tahlil(matn)
turns JSON text into Algorizm values
matn(qiymat[, chekinish])
turns a value into JSON text; with chekinish, on several lines indented by that many spaces
import json
talaba = json.tahlil("{\"ism\": \"Ali\", \"baholar\": [5, 4], \"faol\": true}" )
chiqar (talaba["ism" ], talaba["baholar" ][0 ], talaba["faol" ])
talaba["yosh" ] = 19
chiqar (json.matn(talaba))
chiqar (json.matn({"a" : [1 , 2 ], "b" : bo'sh }, 2 ))Output
Ali 5 rost
{"ism": "Ali", "baholar": [5, 4], "faol": true, "yosh": 19}
{
"a": [
1,
2
],
"b": null
}
JSON
Algorizm
object
lug'at
array
ro'yxat
string
matn
number
butun or kasr
true, false
rost, yolg'on
null
bo'sh
Text that is not valid JSON is an error that urin can catch.
qolip#
A regular expression is a pattern that describes text. qolip finds, tests, replaces and splits text by such patterns.
Name
Meaning
top(q, matn)
the first part of the text that fits the pattern, or bo'sh
hammasi(q, matn)
list of all parts that fit
mosmi(q, matn)
does the whole text fit the pattern
almashtir(q, matn, yangi)
every part that fits replaced by yangi
ajrat(q, matn)
the text split wherever the pattern fits
import qolip
chiqar (qolip.hammasi("\\d+" , "12 olma, 7 anor, 30 uzum" ))
chiqar (qolip.top("[a-z]+@[a-z.]+" , "Aloqa: [email protected] " ))
chiqar (qolip.mosmi("\\+998\\d{9}" , "+998901234567" ))
chiqar (qolip.almashtir("\\s+" , "ortiqcha bo'sh joylar" , " " ))
chiqar (qolip.ajrat("[,;] *" , "olma, anor;uzum" ))Output
["12", "7", "30"]
[email protected]
rost
ortiqcha bo'sh joylar
["olma", "anor", "uzum"]
Pattern
Fits
.
any character except a line end
[abc], [a-z]
one of the characters, or a character in the range
[^abc]
any character except these
\d \w \s
a digit, a letter or digit or _, a whitespace character
\D \W \S
the opposite of each
\b
the edge of a word
^ $
the beginning and the end of the text
* + ?
the item before it zero or more times, one or more times, at most once
{m,n}
the item before it from m to n times
*? +? ??
the same, but as few times as possible
( )
a group
a|b
either a or b
A backslash is written twice inside Algorizm text: the pattern \d+ is written "\\d+".
Patterns work on characters, so Cyrillic and other scripts are matched correctly.
Look-ahead and back-references are not supported. A match is always the whole matched text; groups only group.
Previous Methods
Next The command line