Methods
A method is a function that belongs to a value and is called through a dot: ism.katta(). This page lists the methods of the built-in types. Arguments in square brackets are optional.
Text
Text cannot be changed, so every method returns a new value and leaves the original as it was.
| Method | Meaning |
|---|---|
katta() |
all letters in upper case |
kichik() |
all letters in lower case |
bosh_harf() |
the first letter in upper case |
qirq() |
without the spaces, tabs and line ends at both ends |
ajrat([ajratuvchi]) |
list of the parts between separators; without an argument, splits at any run of whitespace |
qatorlar() |
list of the lines |
almashtir(eski, yangi) |
every occurrence of eski replaced by yangi |
top(x) |
position of the first occurrence of x, or -1 |
sanoq(x) |
how many times x occurs |
boshlanadi(x) |
does the text begin with x |
tugaydi(x) |
does the text end with x |
raqammi() |
does the text consist of digits only |
harfmi() |
does the text consist of letters only |
bo'shliqmi() |
does the text consist of whitespace only |
s = " Salom, Dunyo! "
chiqar(s.qirq(), s.qirq().katta(), s.qirq().kichik())
chiqar("olma,anor,uzum".ajrat(","), "bir ikki uch".ajrat())
chiqar("salom".almashtir("l", "L"), "salom".top("lo"), "banan".sanoq("a"))
chiqar("algorizm".boshlanadi("alg"), "rasm.png".tugaydi(".png"))
chiqar("2026".raqammi(), "abc".harfmi(), " ".bo'shliqmi(), "ali".bosh_harf())
chiqar("bir\nikki".qatorlar())Output
Salom, Dunyo! SALOM, DUNYO! salom, dunyo! ["olma", "anor", "uzum"] ["bir", "ikki", "uch"] saLom 2 2 rost rost rost rost rost Ali ["bir", "ikki"]
Upper and lower case are known for Latin, Latin-1 and Cyrillic letters.
Lists
The first six methods change the list itself.
| Method | Meaning |
|---|---|
qo'sh(x) |
adds an item at the end |
joyla(i, x) |
inserts an item at position i; the following items move right |
o'chir([i]) |
removes the item at position i, or the last one, and returns it |
sarala([f]) |
sorts the list; with f, by f(x) |
teskari() |
reverses the order |
tozala() |
removes all items |
indeks(x) |
position of the first x, or -1 |
nusxa() |
a copy of the list (the items themselves are shared) |
birlashtir([ajratuvchi]) |
the items joined into one text, with the separator between them |
r = [3, 1, 2]
r.qo'sh(5)
r.joyla(1, 9)
chiqar(r, r.indeks(9))
chiqar(r.o'chir(), r.o'chir(0), r)
r.sarala()
chiqar(r)
r.teskari()
nusxa = r.nusxa()
nusxa.tozala()
chiqar(r, nusxa, ["a", "b"].birlashtir(", "))Output
[3, 9, 1, 2, 5] 1 5 3 [9, 1, 2] [1, 2, 9] [9, 2, 1] [] a, b
Dictionaries
| Method | Meaning |
|---|---|
kalitlar() |
list of the keys |
qiymatlar() |
list of the values |
juftlar() |
list of [key, value] pairs |
ol(kalit[, standart]) |
the value under the key; if the key is missing, standart, or bo'sh |
o'chir(kalit) |
removes the key and returns its value; an error if the key is missing |
tozala() |
removes all keys |
nusxa() |
a copy of the dictionary |
d = {"olma": 3, "anor": 5}
chiqar(d.kalitlar(), d.qiymatlar(), d.juftlar())
chiqar(d.ol("olma"), d.ol("uzum"), d.ol("uzum", 0))
chiqar(d.o'chir("olma"), d)Output
["olma", "anor"] [3, 5] [["olma", 3], ["anor", 5]]
3 bo'sh 0
3 {"anor": 5}Sets
| Method | Meaning |
|---|---|
qo'sh(x) |
adds a value; nothing happens if it is already there |
o'chir(x) |
removes a value; an error if it is not there |
birlashma(b) |
new set of the values that are in either set |
kesishma(b) |
new set of the values that are in both sets |
ayirma(b) |
new set of the values that are only in this set |
tozala() |
removes all values |
nusxa() |
a copy of the set |
a = {1, 2, 3, 2, 1}
b = to'plam([3, 4])
chiqar(a, uzunlik(a), 2 ichida a)
chiqar(a.birlashma(b), a.kesishma(b), a.ayirma(b))
a.qo'sh(10)
a.o'chir(1)
chiqar(saralangan(a))
harflar = to'plam("mississippi")
chiqar(uzunlik(harflar), to'plam(), tur({}))Output
{1, 2, 3} 3 rost
{1, 2, 3, 4} {3} {1, 2}
[2, 3, 10]
4 to'plam() lug'atTuples
A tuple cannot be changed, so it has only two methods.
| Method | Meaning |
|---|---|
indeks(x) |
position of the first x, or -1 |
sanoq(x) |
how many times x occurs |
Bytes
| Method | Meaning |
|---|---|
matn() |
the bytes read as UTF-8 text |
o'n_oltilik() |
the bytes as hexadecimal text, two digits for each byte |
b = baytlar("Salom")
chiqar(b, uzunlik(b), b[0], b.o'n_oltilik())
chiqar(baytlar([72, 105]).matn(), baytlar("ў"), uzunlik(baytlar("ў")))Output
baytlar("Salom") 5 83 53616c6f6d
Hi baytlar("ў") 2What works on every collection
Besides methods, these work on text, lists, tuples, sets, dictionaries and ranges alike: uzunlik(x), x ichida y, har … ichida, saralangan, eng_katta, eng_kichik, and conversion with ro'yxat, kortej and to'plam. Indexing x[i] and slices x[a:b] work on text, lists, tuples and bytes.