cb
ABCD
  • Python Суулгах
  • Python Бичиглэл /Syntax/
  • Python Тайлбар оруулах /comments/
  • Python Хувьсагч зарлах /Variables/
  • Python өгөгдлийн төрлүүд /Data Types/
  • Python Тоон төрөл /Numbers/
  • Python хувьсагчийг төрлөөр тодорхойлох /Casting/
  • Python Текст төрлийн хувьсагч /Strings/
  • Python Логик утга /Booleans/
  • Python Опериаторууд /Operators/
  • Python Жагсаалт /lists/
  • Python Багц /Tuples/
  • Python Багц /Set/
  • Python Багц /Dictionaries/
  • Python Нөхцөл шалгах /if ... else/
  • Python Давталт /While Loops/
  • Python Давталт /For Loops/
  • Python Функц /Functions/
  • Python /Масив/ Arrays
  • Python Класс ба Объект /Classes and Objects/
  • Python Удамшил /Inheritance/
  • Python Тоолуур /Iterators/
  • Python Огноо /Date time/
  • Python JSON
  • Python Тогтмол илэрхийлэл /RegEx/
  • Python PIP
  • Python Алдааг шалгах /Try Except/
  • Python Файлтай ажиллах
  • Python Ламбда / Lambda
  • Python Map, Filter, Reduce Функц
тохиргоо
Толгой хэсэг
Хажуугийн самбар
Үндсэн контент
НЭВТРЭХ

Python Тоон төрөл /Numbers/

Python-д гурван тоон төрөл байдаг

  • int
  • float
  • complex

Жишээ нь:

x = 1
y = 2.8
z = 5j
print (type(x)) print (type(y)) print (type(z))

Үр дүн

C:\Users\Pc Name>numbers.py
<class 'int'>
<class 'float'>
<class 'comlex'>

INT

int Буюу Integer нь хязгааргүй урттай эерэг эсвэл сөрөг бүхэл тоо байна.

Жишээ нь:

x = 1
y = 265467987987451238
z = -56465465465465
print (type(x)) print (type(y)) print (type(z))

Үр дүн

C:\Users\Pc Name>numbers.py
<class 'int'>
<class 'int'>
<class 'int'>

FLOAT

Float буюу "Floating point Number" нь эерэг болон сөрөг утгатай бутархай тоо байна.

Жишээ нь:

x = 1.10
y = 2.6
z = -564.65465

print (type(x))
print (type(y))
print (type(z))

Үр дүн

C:\Users\Pc Name>numbers.py
<class 'float'>
<class 'float'>
<class 'float'>

FLOAT

Мөн "E"-ээр илэрхийлэгдсэн олон оронтой тоо нь float төрлөөр илэрхийлэгдэнэ.

Жишээ нь:

x = 1e12
y = 2E656
z = -564.65e465

print (type(x))
print (type(y))
print (type(z))

Үр дүн

C:\Users\Pc Name>numbers.py
<class 'float'>
<class 'float'>
<class 'float'>

COMPLEX

Нийлмэл тоог төсөөллийн хэсэг болгон "j" үсгээр бичнэ.

Жишээ нь:

x = 12 + 3j
y = 4j
z = -5j

print (type(x))
print (type(y))
print (type(z))

Үр дүн

C:\Users\Pc Name>numbers.py
<class 'complex'>
<class 'complex'>
<class 'complex'>

Төрөл хувиргах

Та int(), float(), болон complex() функцүүд ашиглан нэг төрлөөс нөгөөд шилжүүлж болно.

Жишээ нь:

global түлхүүр үгээр зарлагдсан хувьсагч глобал орчинд шууд хамаарна

x = 12     # int
y = 4.8    # float
z = 5j     # complex

# int-ийг float
a = float(x)
# float-ийг int
b = int(y)
# int-ийг complex
c = complex(x)
print (a)
print (b)
print (c)
print (type(a))
print (type(b))
print (type(c))

Үр дүн

C:\Users\Pc Name>numbers.py
12.0
4
12+0j
<class 'float'>
<class 'int'>
<float 'comlex'>

Random Number буюу Санамсаргүй тоо

Python хэлэнд random() функц байхгүй, гэхдээ Random модуль байдаг тул бид ашиглаж болно.

Жишээлбэл:

Импорт командаар random модулийг дуудаж, 1 - 99 хооронд санамсаргүй нэг тоог дэлгэцэд хэвлэж байна.

import random
print (random.randrange(1,100))

Үр дүн

C:\Users\Pc Name>numbers.py
77

Сэтгэгдэлүүд

Batkhuu

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute 'randrange'

Feb. 11, 2020, 4:38 a.m.

madara

print (random.randrange(1, 100)) shu

March 30, 2020, 7:11 a.m.

ABCD.mn

Баярлалаа. Алдаа засагдсан.

March 30, 2020, 11:54 a.m.
Контентын нэр
Python Суулгах
Python Бичиглэл /Syntax/
Python Тайлбар оруулах /comments/
Python Хувьсагч зарлах /Variables/
Python өгөгдлийн төрлүүд /Data Types/
Python Тоон төрөл /Numbers/
Python хувьсагчийг төрлөөр тодорхойлох /Casting/
Python Текст төрлийн хувьсагч /Strings/
Python Логик утга /Booleans/
Python Опериаторууд /Operators/
Python Жагсаалт /lists/
Python Багц /Tuples/
Python Багц /Set/
Python Багц /Dictionaries/
Python Нөхцөл шалгах /if ... else/
Python Давталт /While Loops/
Python Давталт /For Loops/
Python Функц /Functions/
Python /Масив/ Arrays
Python Класс ба Объект /Classes and Objects/
Python Удамшил /Inheritance/
Python Тоолуур /Iterators/
Python Огноо /Date time/
Python JSON
Python Тогтмол илэрхийлэл /RegEx/
Python PIP
Python Алдааг шалгах /Try Except/
Python Файлтай ажиллах
Python Ламбда / Lambda
Python Map, Filter, Reduce Функц
ABCD.mn ©

Нөхцөл & Шаардлага

1. General

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ultrices, justo vel imperdiet gravida, urna ligula hendrerit nibh, ac cursus nibh sapien in purus. Mauris tincidunt tincidunt turpis in porta. Integer fermentum tincidunt auctor.

2. Account

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ultrices, justo vel imperdiet gravida, urna ligula hendrerit nibh, ac cursus nibh sapien in purus. Mauris tincidunt tincidunt turpis in porta. Integer fermentum tincidunt auctor.

3. Service

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ultrices, justo vel imperdiet gravida, urna ligula hendrerit nibh, ac cursus nibh sapien in purus. Mauris tincidunt tincidunt turpis in porta. Integer fermentum tincidunt auctor.

4. Payments

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ultrices, justo vel imperdiet gravida, urna ligula hendrerit nibh, ac cursus nibh sapien in purus. Mauris tincidunt tincidunt turpis in porta. Integer fermentum tincidunt auctor.