---
title: Python Numbers
description: "> ## Python Numbers – Python дахь Тоонууд > > > > There are three numeric types in Python: > > > > Python-д гурван төрлийн тоон утга байдаг > > > > - `int` – Бүхэл тоо > -…"
url: "https://apprentice.mn/docs/python-numbers/"
updated: "2024-07-26"
category: Python
---

# Python Numbers

> ## Python Numbers – Python дахь Тоонууд
>
>
>
> There are three numeric types in Python:
>
>
>
> Python-д гурван төрлийн тоон утга байдаг
>
>
>
> - `int` – Бүхэл тоо
> - `float` – Бутархай тоо
> - `complex` – Нийлмэл тоо

Variables of numeric types are created when you assign a value to them:

Хувьсагчид тоон төрлийн утга оноох үед үүсгэнэ:

#### Example – Жишээ

`x = 1    # inty = 2.8  # floatz = 1j   # complex` 

To verify the type of any object in Python, use the `type()` function:

Python дээр аливаа зүйлсыг шалгахын тулд `type()` функцийг ашиглаарай:

#### Example – Жишээ

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

## Int – Бүхэл тоо

Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.

Int, буюу integer нь бүхэл тоо бөгөөд эерэг эсвэл сөрөг, хязгааргүй урттай.

#### Example – Жишээ

`x = 1y = 35656222554887711z = -3255522print(type(x))print(type(y))print(type(z))`

## Float – Бутархай тоо

Float, or “floating point number” is a number, positive or negative, containing one or more decimals.

Float буюу “floating point number” нь нэг эсвэл хэд хэдэн аравтын бутархай агуулсан эерэг эсвэл сөрөг тоо.

#### Example – Жишээ

Floats:

Бутархай тоонууд:

`x = 1.10y = 1.0z = -35.59print(type(x))print(type(y))print(type(z))`

Float can also be scientific numbers with an “e” to indicate the power of 10.

Float нь мөн “e” гэсэн тэмдэглэгээтэйгээр 10-ын зэргийн тэмдэглэгээтэйгээр бичигдэж болно.

#### Example – Жишээ

Floats:

Бутархай тоонууд:

`x = 35e3y = 12E4z = -87.7e100print(type(x))print(type(y))print(type(z))`

## Complex – Нийлмэл тоо

Complex numbers are written with a “j” as the imaginary part:

Complex тоо нь “j” гэсэн тэмдэглэгээтэйгээр дүрслэгддэг.

#### Example – Жишээ

Complex:

Нийлмэл тоо:

`x = 3+5jy = 5jz = -5jprint(type(x))print(type(y))print(type(z))`

## Type Conversion – Төрөл Хувиргах

You can convert from one type to another with the `int()`, `float()`, and `complex()` methods:

`int()`, `float()`, болон `complex()` аргуудыг ашиглан нэг төрлөөс нөгөө рүү хөрвүүлж болно:

#### Example – Жишээ

Convert from one type to another:

Нэг төрлөөс нөгөө төрөл рүү хүрвүүлэх:

`x = 1     # inty = 2.8   # floatz = 1j    # 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))`

**Note:** You cannot convert complex numbers into another number type.

**Тэмдэглэл:**Complex тоог өөр төрлийн тоонд хөрвүүлж болохгүй.

## Random Number – Санамсаргүй тоо

Python does not have a `random()` function to make a random number, but Python has a built-in module called `random` that can be used to make random numbers:

Python нь `random()` функцгүй боловч, Python нь санамсаргүй тоо үүсгэх `random` гэсэн суурилуулсан модулийг агуулдаг.

#### Example – Жишээ

Import the random module, and display a random number between 1 and 9:

random модуль(солигч эд анги) оруулж, 1-ээс 9 хүртлэх тоог санамсаргүй байдлаар харуулна:

`import random
print(random.randrange(1, 10))`

        [https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-numbers%2F&linkname=Python%C2%A0Numbers](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-numbers%2F&linkname=Python%C2%A0Numbers)[https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-numbers%2F&linkname=Python%C2%A0Numbers](https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-numbers%2F&linkname=Python%C2%A0Numbers)[https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-numbers%2F&linkname=Python%C2%A0Numbers](https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-numbers%2F&linkname=Python%C2%A0Numbers)[https://www.addtoany.com/share](https://www.addtoany.com/share)
