03 String, Range, List, some functions

image.png Խաչիկ, Վայոց ձոր, լուսանկարի հղումը Հեղինակ՝ Ani Adiglozalyan

Open In Colab (Կարողա մի թեթև հին լինի կոլաբում նյութը)

Shindler’s [509, "Պանիր"]
(c) John Williams

🎦 Տեսադասեր + լրացուցիչ

ToDo 1. Տեսություն 2025
2. Տեսություն 2023
3. Գործնական 2025
4. Գործնական 2023
5. Որոշ տնայինների լուծումներ

Նշումներ։

Դասընթացին մասնակցության ու կարծիք հայտնելու Google Form

📚 Նյութը

Տողեր (string)

Տողերի ստեղծում և escape(/)

a = """Բարևներ""" # նույննա ինչ մի չակերտով ՝ a = "Բարևներ"
print(a)
print(type(a))
Բարևներ
<class 'str'>
# 1
print(1) 
a = '''asdasgudasfafsf 
sdfsdfsdfs'''
print(2) 

print(a)
1
2
asdasgudasfafsf
sdfsdfsdfs
a = "Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, \n \
Թութը թափ եք տալիս, \
ուրիշ ինչ կա չկա, \
դե լավ դե լավ մնացեք \
" # '''
print(a)
Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք 
a = 'Cheese' 
b = 'Hayk's cheese'

print(a)
print(b)
Cheese
Hayk's cheese
# Կարող ենք ուղղել հետևյալ կերպ
b = "Hayk\"s cheese"
print(b)
Hayk"s cheese

(double click before reading)

Երբ նոր տող գնալիս էինք գրում, իրականում ահա թե ինչ էր տեղի ունենում՝

Python-ը տեսնում էր  նշանը, գիտեր որ դա հատուկ նշանա ու պետքա ասի իրեն թե ինքը ինչ անի հաջորդ քայլում, եթե տեսնի n գնա հաջորդ տող, որոշ այլ բաներ ունի նաև

  1.  - escape character
  2. ' - ’
  3. " - ”
  4. tab
  5. - new line
  6. \ -
print('Hayk\\s cheese')
Hayk\s cheese
print('Hayk\ns cheese')
Hayk
s cheese
print('Hayk\ts cheese')

print('Hayk\\s cheese')

print("\"Hayk\'s cheese\"")
Hayk    s cheese
Hayk\s cheese

String-երով գործողություններ

Գումարում

skizb = "Ես տողի սկիզբն եմ"
verj = 'ես էլ վերջը'
print(skizb + verj)
Ես տողի սկիզբն եմես էլ վերջը
print(skizb + " - " + verj) # print(skizb, verj, sep=" - ")
Ես տողի սկիզբն եմ - ես էլ վերջը
print(skizb + 1231231231 + verj + 'պանիր')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 print(skizb + 1231231231 + verj + 'պանիր')

TypeError: can only concatenate str (not "int") to str
# կարանք մի քանի հատ գումարենք միանգամից
print(skizb + str(1231231231) + verj + 'պանիր')
Ես տողի սկիզբն եմ1231231231ես էլ վերջըպանիր
print('2' + "2")
22
print('2' + True)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [21], in <cell line: 1>()
----> 1 print('2' + True)

TypeError: can only concatenate str (not "bool") to str

Բազմապատկում

a = 'բարև'

# 5 * 3
# 5 + 5 + 5
print("*")
print("*" * 2)
print("*" * 3) # "*" + "*" + "*"
print("*" * 4)

print("*"*4.5) # problem
*
**
***
****
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [13], in <cell line: 6>()
      3 print("*" * 3) # "*" + "*" + "*"
      4 print("*" * 4)
----> 6 print("*"*4.5) # problem

TypeError: can't multiply sequence by non-int of type 'float'
print(a * 4)
print(a + "1"*4)
print((a + " ") * 4)
Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք 
Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք 1111
Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք  Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք  Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք  Բարևներ, ինչ կա չկա, էլի են հին տներն եք մնում, 
 Թութը թափ եք տալիս, ուրիշ ինչ կա չկա, դե լավ դե լավ մնացեք  
print(a * 3 + " " + '$' *4)
բարևբարևբարև $$$$

Հստակ նիշեր վերցնել (indexing, slicing)

indexing

a = 'Բարև'
print(a)
print(len(a)) # len('Բարև') length
Բարև
4
print("Բարև"[0])
print(a[3])
Բ
և
b = "asdfghkhreadsfgjygfadsfhytsdfhytsfdacdvgfh"
print(b[-1])
h
print(a[4])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Input In [31], in <cell line: 1>()
----> 1 print(a[4])

IndexError: string index out of range
print(b[-3])
g
print(a[4-1])
և
print(a[len(a) - 1]) # ի՞նչ կտպի ըստ ձեզ
և
print(a[len(a)-1])
և
print(a[-3])
ա

python indexing.png

python indexing.png
print(a[2])
print(a[-2]) # len(a) - 2 -> 4 - 2 = 2
ր
ր

slicing

print(a[0:-4]) # սկիզբը ներառյալ, վերջը չէ
# a[0] + a[1] (a[2]-ը չկա)

# -4-1 -> -5 + 4 -> -1
print(a[0:12345678]) # a[4]-ը չի աշխատում, բայց ստեղ գրում ենք մինչև 4, դա հենց նրանիցա որ վերջը չենք վերցնում
Բարև
print(a[0:412345678])
Բարև
print(a[0:2])
print(a[:2]) # եթե բաց թողենք առաջին թիվը կհասկանա որ ուղղակի զրոյիցա սկսվում
Բա
Բա
print(a[1:4])
print(a[1:]) # նույն ձև էլ երկրորդը բաց թողելով հասկանումա որ մինչև վերջ ենք ուզում
արև
արև
print(a[-3:-1])
print(a[1:3])
ար
ար

կարող ենք նաև թռինչք ունենալ

a = 'abcdefghk'
a['սկսի ստեղից':'գնա մինչև ստեղ(ոչ ներառյալ)':'այ էսքան մեծ քայլով']
print(a[2:5:2])
ce
# abcdefghk
print(a[::-2])
kgeca
print(a[8:2:-1])
khgfed
print(a[::-1]) # a[4:6:1]
khgfedcba
print(a[::-1])
khgfedcba
print(a[3:7]) # 7 - 3
defg
print(len(a))
9
print(a[8::-1])
khgfedcba
a[3:6] # -> 6-3 = 3
'def'
print(a[::2])
13579
print(a[1::2])
2468
print(a[7:0:-2])
8642
# 123456789
print(a[6:]) # a[x:y] -> y-x
789
print(a)
a = "abcdef"
abcdef
print(a[-36:6000]) # ...123456789......
  File "<ipython-input-56-98a858089493>", line 1
    print([-36:6000]) # ...123456789......
              ^
SyntaxError: invalid syntax
a = "abcdefgh"
print(a[-4:-2]) # a[8-4:8-2] -> a[4:6]
print(a[4:6])
ef
ef
print(a + '___' + a[::-1])
abcdefghk___khgfedcba
a = '123456789'
# print(a[2:8:-1])
print(a[3:1:-1])
print(a[1:3])
43
234
a[3:19:4]

# 3, 7 (3+4), 11 (7 + 4), 15 (11 + 4)

# 13, 100, 4

a = "01234567891011"
print(a[2:8:3])
25

Range (string-երի թեմայից չի)

# a = '0123456789'

# [1:9:3] -> 1, 4, 7
# a[1] + a[4] + a[7]
# print(a[1:4])


print(range(-3,4)) # a[1:4]
print(list(range(-3, 4)))
print(type(range(-3,4)))

print(a)
print(a[1:4])
range(-3, 4)
[-3, -2, -1, 0, 1, 2, 3]
<class 'range'>
abcdefghk
bcd
a = '0123456789'
print(a[1:15:-1]) #-> 1, 4, 7
98765432
print(list(range(30, 15, -3))) # a[1:15:3]
[30, 27, 24, 21, 18]
# list(range(3,10,2))
# a[3:10:2]

a = "abcd"
print(a[1:4])
print(list(range(1,4)))
bcd
[1, 2, 3]
# print(list(range(10,15,3)))
# print(list(range(18, 10, -1.5)))

# ...2..5.8 9 10 11 12 13 14 15 16 17 18

print(list(range(10,15,-3)))

range(10,15, 2)
range(1, 100000000, 3)
[]
# a[:15]
list(range(15)) # range(0,15)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
a[3:]
# համարժեքը չկա
# a[2:15]
list(range(2, 15)) # range(2,15,1)
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
# a[2:15:3]
list(range(2, 1, -8)) # try also 2, 11,1

# -7 -6 -5 ... -1 0 1 2
# -7 -6 -5 ... -1 0 1 2 3
[2]
list(range(-4, 1, 2)) # սկիզբ, ավարտ, քայլ
[-4, -2, 0]
list(range(1, 5, -2))
[]

Formatting

Formated string

հավես բաներ որոնք կարելի ա f string-երով անել. կարճ վիդեո

anun = 'John'
azganun = "Smith"
tariq = 25
# Ներկայացնել John-ին
print('Իմ անունն', anun, 'է, իսկ ազգանունը', azganun, "ես", tariq, "տարեկան եմ")
Իմ անունն John է, իսկ ազգանունը Smith ես 25 տարեկան եմ
# Ներկայացնել John-ին
print('Իմ անունն', anun, 'է, իսկ ազգանունը', azganun, "ես", tariq, "տարեկան եմ")
Իմ անունն John է, իսկ ազգանունը Smith ես 25 տարեկան եմ
print('Իմ անունն anun, է իսկ ազգանունը azganun ես tariq տարեկան եմ')
Իմ անունն anun, է իսկ ազգանունը azganun ես tariq տարեկան եմ
print('Իմ անուննը {} է իսկ ազգանունը {} ես {} տարեկան եմ'.format(anun, azganun, tariq))
Իմ անուննը John է իսկ ազգանունը Smith ես 25 տարեկան եմ
text = 'Իմ անուննը {anun} է իսկ ազգանունը {azganun} ես {tariq} տարեկան եմ'
print(text)
Իմ անուննը {anun} է իսկ ազգանունը {azganun} ես {tariq} տարեկան եմ
print(f"Իմ անուննը՝{anun} է իսկ ազգանունը {azganun} ես {tariq} տարեկան եմ")
Իմ անուննը՝John է իսկ ազգանունը Smith ես 25 տարեկան եմ
print(f"Իմ անուննը {anun} է իսկ ազգանունը {azganun+'յան'} ես {tariq+4} տարեկան եմ")
Իմ անուննը John է իսկ ազգանունը Smithյան ես 29 տարեկան եմ
print(anun, azganun, sep="-") # չենք կարա վերագրենք փոփ․
John-Smith
name = f"{anun}-{azganun}"
print(name)
John-Smith
print(f"Իմ անուննը {anun} է իսկ ազգանունը {azganun} հաջորդ տարի ես կլինեմ {tariq + 1} տարեկան")
Իմ անուննը John է իսկ ազգանունը Smith հաջորդ տարի ես կլինեմ 26 տարեկան
shat_erkar_popoghakan = 4
print(shat_erkar_popoghakan)
print(f"shat_erkar_popoghakan = {shat_erkar_popoghakan = }")
print(f"{shat_erkar_popoghakan = }")

# print(f"""{a} 
# {x} = {a *3}
# """)
4
shat_erkar_popoghakan = shat_erkar_popoghakan =    4
shat_erkar_popoghakan =        4

num = 5.123456432

print(f"{num:.0f}")

a = f"{num:.1f}"
print(a, type(a))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [66], in <cell line: 3>()
      1 num = 5.123456432
----> 3 print(f"{num:.0r}")
      5 a = f"{num:.1f}"
      6 print(a, type(a))

ValueError: Unknown format code 'r' for object of type 'float'
surname = "ազգանունը {}"
print(surname)

surname_input = input()

print(surname.format(surname_input))
ազգանունը {}
ազգանունը TArk

Raw string

print('ես առաջին տողն եմ \n ես էլ երկրորդ')
ես առաջին տողն եմ 
 ես էլ երկրորդ
a = r'ես առաջին տողն եմ \n ես էլ երկրորդ'
print(a)
ես առաջին տողն եմ \n ես էլ երկրորդ
print(a)
ես առաջին տողն եմ \n ես էլ երկրորդ
print("Desktop\tut\nur.txt")
Desktop ut
ur.txt
print("Desktop\\tut\\nur.txt")
Desktop\tut\nur.txt
print(r"Desktop\tut\nur.txt")
Desktop\tut\nur.txt

Immutability

s = 'պրնիր'
s[1] = "ա"
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [77], in <cell line: 1>()
----> 1 s[1] = "ա"

TypeError: 'str' object does not support item assignment
# s[1] = "ր"
s = "պանիր"
print(s)
պանիր
s = s[0] + "ա" + s[2:]
print(s)
պանիր

in

s = 'աղցան սոխ'
print('ա' in s)
print('ան' in s)
True
True
print('ղա' in s)
print('աղ' in s)
False
True
print('բիբառ' in s)
False

List (ցուցակ)

Հայտարարումը

a = [1, 3.14, "կարտոֆիլ", [25,33], 5]

print(a)
print(type(a))
print(a[1:3])
print(list(range(1,3)))
[1, 3.14, 'կարտոֆիլ', [25, 33], 5]
<class 'list'>
[3.14, 'կարտոֆիլ']
[1, 2]
1 3.14 կարտոֆիլ [25, 33] 5
print(a[1])
3.14
print(a[-1])
5
print(a[2:4])
['կարտոֆիլ', [25, 33]]
print(a[3])

print(a[3][1])

print([25, 33][1])
[25, 33]
33
33
a[:3]
[1, 3.14, 'կարտոֆիլ']
a = [1,
     5,
     3,
     50,
     9]
print(a)
[1, 5, 3, 50, 9]
# s[1] = "ա"
a[0] = 509
print(a) # mutable
[509, 5, 3, 50, 9]
print(12 in a)
print(11 in a)
False
False
a = list("barev")
print(a)

print(str([1,2,3]))
['b', 'a', 'r', 'e', 'v']
[

Գումարում, թվով բազմապատկում

b = [2, 4, 6]
print(b)

print(a)
[2, 4, 6]
[509, 5, 3, 50, 9]
a + b
[509, 5, 3, 50, 9, 2, 4, 6]
b * 3
[2, 4, 6, 2, 4, 6, 2, 4, 6]
print(b)
[2, 4, 6]
b += [5]
b
[2, 4, 6, 5]
# b = b + 5 # b += 5
b = b + [5]
b += [5]
print(b)
[2, 4, 6, 5, 5, 5]
a.append(5)

a.append([1,2, 4])

# a = a.append(5)

print(a)
[509, 5, 3, 50, 9, 5, [1, 2, 4], 5, [1, 2, 4]]
del a[2] # delete
a
[509, 5, 5, [1, 2, 4], 5, [1, 2, 4]]

ցուցակների վրա հաճախ կիրառվող ֆունկցիաներ (հրամաններ)

Any / All

surnames = ["dartanyan", "heshyan", "panir"]

all([i.endswith("yan") for i in surnames])

# all - everything is true
any([i.endswith("yan") for i in surnames])
False
conditions = [False, False, True]
print(any(conditions))  # Output: True
checks = [True, True, True]
print(all(checks))  # Output: True
passwords = ["abc123", "secure!", "longpassword"]
print(all(len(p) >= 6 for p in passwords))  # Output: True

sum, len, max, min

a = [1, 3.4, 654, 143]
print(sum(a))
801.4
print(max(a))
654
print(min(a))
1
print(len(a)) # length
4

Թվերի վրա հաճախ կիրառվող ֆունկցիաներ (հրամաններ)

a = -509
print(abs(a)) # absolute value, բացարձակ արժեք, մոդուլ
509
a = 4 # a**3
print(pow(a, (1/3))) # power ասիճան pow(a, b) նշանակումա a-ի b աստիճան
0.6299605249474366
a = 3.14159
b = 3.89
# print(round(a))
print(f"{a}-ն կլորացնենք -> {round(a)}")
print(f"{b}-ն կլորացնենք -> {round(b)}")

print(round(3.5))

print(round(-3.7))

print(round(a, 3)) # ստորակետից հետո քանի նիշի ճշտությամբ ենք ուզում կլորացնել
3.14159-ն կլորացնենք -> 3
3.89-ն կլորացնենք -> 4
4
-4
3.142
cos(3)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [169], in <cell line: 1>()
----> 1 cos(3)

NameError: name 'cos' is not defined

Մեծացնենք մեր ֆունկցիաների հավաքածուն

math

import math # import-ների մասին դեռ կխոսենք
a = 3.5

print(math.ceil(a)) # առաստաղ
print(math.floor(a)) # հատակ # int(a)
4
3
import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
from math import ceil, floor

a = 3.5
print(ceil(a)) # առաստաղ
print(floor(a)) # հատակ
4
3
a = 25
print(math.sqrt(a)) # square root, քառակուսի արմատ
5.0
a = 0
print(math.cos(a))
1.0
help(math)
Help on built-in module math:

NAME
    math

DESCRIPTION
    This module provides access to the mathematical functions
    defined by the C standard.

FUNCTIONS
    acos(x, /)
        Return the arc cosine (measured in radians) of x.
        
        The result is between 0 and pi.
    
    acosh(x, /)
        Return the inverse hyperbolic cosine of x.
    
    asin(x, /)
        Return the arc sine (measured in radians) of x.
        
        The result is between -pi/2 and pi/2.
    
    asinh(x, /)
        Return the inverse hyperbolic sine of x.
    
    atan(x, /)
        Return the arc tangent (measured in radians) of x.
        
        The result is between -pi/2 and pi/2.
    
    atan2(y, x, /)
        Return the arc tangent (measured in radians) of y/x.
        
        Unlike atan(y/x), the signs of both x and y are considered.
    
    atanh(x, /)
        Return the inverse hyperbolic tangent of x.
    
    ceil(x, /)
        Return the ceiling of x as an Integral.
        
        This is the smallest integer >= x.
    
    comb(n, k, /)
        Number of ways to choose k items from n items without repetition and without order.
        
        Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates
        to zero when k > n.
        
        Also called the binomial coefficient because it is equivalent
        to the coefficient of k-th term in polynomial expansion of the
        expression (1 + x)**n.
        
        Raises TypeError if either of the arguments are not integers.
        Raises ValueError if either of the arguments are negative.
    
    copysign(x, y, /)
        Return a float with the magnitude (absolute value) of x but the sign of y.
        
        On platforms that support signed zeros, copysign(1.0, -0.0)
        returns -1.0.
    
    cos(x, /)
        Return the cosine of x (measured in radians).
    
    cosh(x, /)
        Return the hyperbolic cosine of x.
    
    degrees(x, /)
        Convert angle x from radians to degrees.
    
    dist(p, q, /)
        Return the Euclidean distance between two points p and q.
        
        The points should be specified as sequences (or iterables) of
        coordinates.  Both inputs must have the same dimension.
        
        Roughly equivalent to:
            sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
    
    erf(x, /)
        Error function at x.
    
    erfc(x, /)
        Complementary error function at x.
    
    exp(x, /)
        Return e raised to the power of x.
    
    expm1(x, /)
        Return exp(x)-1.
        
        This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.
    
    fabs(x, /)
        Return the absolute value of the float x.
    
    factorial(x, /)
        Find x!.
        
        Raise a ValueError if x is negative or non-integral.
    
    floor(x, /)
        Return the floor of x as an Integral.
        
        This is the largest integer <= x.
    
    fmod(x, y, /)
        Return fmod(x, y), according to platform C.
        
        x % y may differ.
    
    frexp(x, /)
        Return the mantissa and exponent of x, as pair (m, e).
        
        m is a float and e is an int, such that x = m * 2.**e.
        If x is 0, m and e are both 0.  Else 0.5 <= abs(m) < 1.0.
    
    fsum(seq, /)
        Return an accurate floating point sum of values in the iterable seq.
        
        Assumes IEEE-754 floating point arithmetic.
    
    gamma(x, /)
        Gamma function at x.
    
    gcd(*integers)
        Greatest Common Divisor.
    
    hypot(...)
        hypot(*coordinates) -> value
        
        Multidimensional Euclidean distance from the origin to a point.
        
        Roughly equivalent to:
            sqrt(sum(x**2 for x in coordinates))
        
        For a two dimensional point (x, y), gives the hypotenuse
        using the Pythagorean theorem:  sqrt(x*x + y*y).
        
        For example, the hypotenuse of a 3/4/5 right triangle is:
        
            >>> hypot(3.0, 4.0)
            5.0
    
    isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)
        Determine whether two floating point numbers are close in value.
        
          rel_tol
            maximum difference for being considered "close", relative to the
            magnitude of the input values
          abs_tol
            maximum difference for being considered "close", regardless of the
            magnitude of the input values
        
        Return True if a is close in value to b, and False otherwise.
        
        For the values to be considered close, the difference between them
        must be smaller than at least one of the tolerances.
        
        -inf, inf and NaN behave similarly to the IEEE 754 Standard.  That
        is, NaN is not close to anything, even itself.  inf and -inf are
        only close to themselves.
    
    isfinite(x, /)
        Return True if x is neither an infinity nor a NaN, and False otherwise.
    
    isinf(x, /)
        Return True if x is a positive or negative infinity, and False otherwise.
    
    isnan(x, /)
        Return True if x is a NaN (not a number), and False otherwise.
    
    isqrt(n, /)
        Return the integer part of the square root of the input.
    
    lcm(*integers)
        Least Common Multiple.
    
    ldexp(x, i, /)
        Return x * (2**i).
        
        This is essentially the inverse of frexp().
    
    lgamma(x, /)
        Natural logarithm of absolute value of Gamma function at x.
    
    log(...)
        log(x, [base=math.e])
        Return the logarithm of x to the given base.
        
        If the base not specified, returns the natural logarithm (base e) of x.
    
    log10(x, /)
        Return the base 10 logarithm of x.
    
    log1p(x, /)
        Return the natural logarithm of 1+x (base e).
        
        The result is computed in a way which is accurate for x near zero.
    
    log2(x, /)
        Return the base 2 logarithm of x.
    
    modf(x, /)
        Return the fractional and integer parts of x.
        
        Both results carry the sign of x and are floats.
    
    nextafter(x, y, /)
        Return the next floating-point value after x towards y.
    
    perm(n, k=None, /)
        Number of ways to choose k items from n items without repetition and with order.
        
        Evaluates to n! / (n - k)! when k <= n and evaluates
        to zero when k > n.
        
        If k is not specified or is None, then k defaults to n
        and the function returns n!.
        
        Raises TypeError if either of the arguments are not integers.
        Raises ValueError if either of the arguments are negative.
    
    pow(x, y, /)
        Return x**y (x to the power of y).
    
    prod(iterable, /, *, start=1)
        Calculate the product of all the elements in the input iterable.
        
        The default start value for the product is 1.
        
        When the iterable is empty, return the start value.  This function is
        intended specifically for use with numeric values and may reject
        non-numeric types.
    
    radians(x, /)
        Convert angle x from degrees to radians.
    
    remainder(x, y, /)
        Difference between x and the closest integer multiple of y.
        
        Return x - n*y where n*y is the closest integer multiple of y.
        In the case where x is exactly halfway between two multiples of
        y, the nearest even value of n is used. The result is always exact.
    
    sin(x, /)
        Return the sine of x (measured in radians).
    
    sinh(x, /)
        Return the hyperbolic sine of x.
    
    sqrt(x, /)
        Return the square root of x.
    
    tan(x, /)
        Return the tangent of x (measured in radians).
    
    tanh(x, /)
        Return the hyperbolic tangent of x.
    
    trunc(x, /)
        Truncates the Real x to the nearest Integral toward 0.
        
        Uses the __trunc__ magic method.
    
    ulp(x, /)
        Return the value of the least significant bit of the float x.

DATA
    e = 2.718281828459045
    inf = inf
    nan = nan
    pi = 3.141592653589793
    tau = 6.283185307179586

FILE
    (built-in)

help(math.sqrt)
Help on built-in function sqrt in module math:

sqrt(x, /)
    Return the square root of x.
help(math)
Help on built-in module math:

NAME
    math

DESCRIPTION
    This module provides access to the mathematical functions
    defined by the C standard.

FUNCTIONS
    acos(x, /)
        Return the arc cosine (measured in radians) of x.
        
        The result is between 0 and pi.
    
    acosh(x, /)
        Return the inverse hyperbolic cosine of x.
    
    asin(x, /)
        Return the arc sine (measured in radians) of x.
        
        The result is between -pi/2 and pi/2.
    
    asinh(x, /)
        Return the inverse hyperbolic sine of x.
    
    atan(x, /)
        Return the arc tangent (measured in radians) of x.
        
        The result is between -pi/2 and pi/2.
    
    atan2(y, x, /)
        Return the arc tangent (measured in radians) of y/x.
        
        Unlike atan(y/x), the signs of both x and y are considered.
    
    atanh(x, /)
        Return the inverse hyperbolic tangent of x.
    
    ceil(x, /)
        Return the ceiling of x as an Integral.
        
        This is the smallest integer >= x.
    
    comb(n, k, /)
        Number of ways to choose k items from n items without repetition and without order.
        
        Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates
        to zero when k > n.
        
        Also called the binomial coefficient because it is equivalent
        to the coefficient of k-th term in polynomial expansion of the
        expression (1 + x)**n.
        
        Raises TypeError if either of the arguments are not integers.
        Raises ValueError if either of the arguments are negative.
    
    copysign(x, y, /)
        Return a float with the magnitude (absolute value) of x but the sign of y.
        
        On platforms that support signed zeros, copysign(1.0, -0.0)
        returns -1.0.
    
    cos(x, /)
        Return the cosine of x (measured in radians).
    
    cosh(x, /)
        Return the hyperbolic cosine of x.
    
    degrees(x, /)
        Convert angle x from radians to degrees.
    
    dist(p, q, /)
        Return the Euclidean distance between two points p and q.
        
        The points should be specified as sequences (or iterables) of
        coordinates.  Both inputs must have the same dimension.
        
        Roughly equivalent to:
            sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
    
    erf(x, /)
        Error function at x.
    
    erfc(x, /)
        Complementary error function at x.
    
    exp(x, /)
        Return e raised to the power of x.
    
    expm1(x, /)
        Return exp(x)-1.
        
        This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.
    
    fabs(x, /)
        Return the absolute value of the float x.
    
    factorial(x, /)
        Find x!.
        
        Raise a ValueError if x is negative or non-integral.
    
    floor(x, /)
        Return the floor of x as an Integral.
        
        This is the largest integer <= x.
    
    fmod(x, y, /)
        Return fmod(x, y), according to platform C.
        
        x % y may differ.
    
    frexp(x, /)
        Return the mantissa and exponent of x, as pair (m, e).
        
        m is a float and e is an int, such that x = m * 2.**e.
        If x is 0, m and e are both 0.  Else 0.5 <= abs(m) < 1.0.
    
    fsum(seq, /)
        Return an accurate floating point sum of values in the iterable seq.
        
        Assumes IEEE-754 floating point arithmetic.
    
    gamma(x, /)
        Gamma function at x.
    
    gcd(*integers)
        Greatest Common Divisor.
    
    hypot(...)
        hypot(*coordinates) -> value
        
        Multidimensional Euclidean distance from the origin to a point.
        
        Roughly equivalent to:
            sqrt(sum(x**2 for x in coordinates))
        
        For a two dimensional point (x, y), gives the hypotenuse
        using the Pythagorean theorem:  sqrt(x*x + y*y).
        
        For example, the hypotenuse of a 3/4/5 right triangle is:
        
            >>> hypot(3.0, 4.0)
            5.0
    
    isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)
        Determine whether two floating point numbers are close in value.
        
          rel_tol
            maximum difference for being considered "close", relative to the
            magnitude of the input values
          abs_tol
            maximum difference for being considered "close", regardless of the
            magnitude of the input values
        
        Return True if a is close in value to b, and False otherwise.
        
        For the values to be considered close, the difference between them
        must be smaller than at least one of the tolerances.
        
        -inf, inf and NaN behave similarly to the IEEE 754 Standard.  That
        is, NaN is not close to anything, even itself.  inf and -inf are
        only close to themselves.
    
    isfinite(x, /)
        Return True if x is neither an infinity nor a NaN, and False otherwise.
    
    isinf(x, /)
        Return True if x is a positive or negative infinity, and False otherwise.
    
    isnan(x, /)
        Return True if x is a NaN (not a number), and False otherwise.
    
    isqrt(n, /)
        Return the integer part of the square root of the input.
    
    lcm(*integers)
        Least Common Multiple.
    
    ldexp(x, i, /)
        Return x * (2**i).
        
        This is essentially the inverse of frexp().
    
    lgamma(x, /)
        Natural logarithm of absolute value of Gamma function at x.
    
    log(...)
        log(x, [base=math.e])
        Return the logarithm of x to the given base.
        
        If the base not specified, returns the natural logarithm (base e) of x.
    
    log10(x, /)
        Return the base 10 logarithm of x.
    
    log1p(x, /)
        Return the natural logarithm of 1+x (base e).
        
        The result is computed in a way which is accurate for x near zero.
    
    log2(x, /)
        Return the base 2 logarithm of x.
    
    modf(x, /)
        Return the fractional and integer parts of x.
        
        Both results carry the sign of x and are floats.
    
    nextafter(x, y, /)
        Return the next floating-point value after x towards y.
    
    perm(n, k=None, /)
        Number of ways to choose k items from n items without repetition and with order.
        
        Evaluates to n! / (n - k)! when k <= n and evaluates
        to zero when k > n.
        
        If k is not specified or is None, then k defaults to n
        and the function returns n!.
        
        Raises TypeError if either of the arguments are not integers.
        Raises ValueError if either of the arguments are negative.
    
    pow(x, y, /)
        Return x**y (x to the power of y).
    
    prod(iterable, /, *, start=1)
        Calculate the product of all the elements in the input iterable.
        
        The default start value for the product is 1.
        
        When the iterable is empty, return the start value.  This function is
        intended specifically for use with numeric values and may reject
        non-numeric types.
    
    radians(x, /)
        Convert angle x from degrees to radians.
    
    remainder(x, y, /)
        Difference between x and the closest integer multiple of y.
        
        Return x - n*y where n*y is the closest integer multiple of y.
        In the case where x is exactly halfway between two multiples of
        y, the nearest even value of n is used. The result is always exact.
    
    sin(x, /)
        Return the sine of x (measured in radians).
    
    sinh(x, /)
        Return the hyperbolic sine of x.
    
    sqrt(x, /)
        Return the square root of x.
    
    tan(x, /)
        Return the tangent of x (measured in radians).
    
    tanh(x, /)
        Return the hyperbolic tangent of x.
    
    trunc(x, /)
        Truncates the Real x to the nearest Integral toward 0.
        
        Uses the __trunc__ magic method.
    
    ulp(x, /)
        Return the value of the least significant bit of the float x.

DATA
    e = 2.718281828459045
    inf = inf
    nan = nan
    pi = 3.141592653589793
    tau = 6.283185307179586

FILE
    (built-in)

random

import random
print(random.randint(2, 20)) # երկու եզրն էլ ներառյալ
16
lst = ["rock", "paper", "scissors"]

print(random.choice(lst))
rock

🏡Տնային

Հիմնական տնային

  1. Profound բաժին 9 (Փոփոխականներ և տիպեր) - 11-ից մինչև վերջ
  2. Profound բաժին 11 (Տողեր) - լրիվ
  3. Profound բաժին 13 (Ցուցակներ և միջակայքեր) - լրիվ

Նշումներ

  • 13.17-ը range օգտագործելով փորձեք լուծել

Լուծումներ

🛠️ Գործնական (ToDo)

Տեսագրությունը (ToDo)

🎲 3

Flag Counter