---
title: Python Comments
description: "> Comments can be used to explain Python code. > > > > Тайлбаруудыг Python кодыг тайлбарлахад ашиглаж болно. > > > > Comments can be used to make the code more readable. > > > > Тайлбарууд нь кодыг…"
url: "https://apprentice.mn/docs/python-comments/"
updated: "2024-07-26"
category: Python
---

# Python Comments

> Comments can be used to explain Python code.
>
>
>
> Тайлбаруудыг Python кодыг тайлбарлахад ашиглаж болно.
>
>
>
> Comments can be used to make the code more readable.
>
>
>
> Тайлбарууд нь кодыг илүү уншихад хялбар болгох боломжтой.
>
>
>
> Comments can be used to prevent execution when testing code.
>
>
>
> Тайлбаруудыг код туршиж байхад үр дүнд оруулахгүй гэж ашиглаж болно.

## Creating a Comment – Тайлбар үүсгэх

Comments starts with a `#`, and Python will ignore them:

Тайлбарууд `#` тэмдэгтээр эхэлдэг бөгөөд Python тэдгээрийг алгасна:

#### Example – Жишээ

`# Тэмдэгт тавиж өгсөн тохиолдолд энэ мөрийг код уншихгүй ажилна.print("Hello, World!")` 

Comments can be placed at the end of a line, and Python will ignore the rest of the line:

Тайлбаруудыг мөрийн төгсгөлд байрлуулж болно, мөн Python тухайн мөрийн үлдсэн хэсгийг алгасна:

#### Example – Жишээ

`print("Hello, World!") # Энэ бол тайлбар`

A comment does not have to be text that explains the code, it can also be used to prevent Python from executing code:

Тайлбар нь кодыг тайлбарлах текст байх албагүй, бас Python кодонд хэрэглэхгүй байх үед ашиглаж болно:

#### Example – Жишээ

`#print("Hello, World!")print("Cheers, Mate!")`

## Multiline Comments – Олон мөрний Тайлбар

Python does not really have a syntax for multiline comments.

Python-д олон мөртэй тайлбар бичих өгүүлбэр зүйд үнэхээр байдаггүй.

To add a multiline comment you could insert a `#` for each line:

Олон мөртэй тайлбар нэмэхийн тулд мөр бүрт `#` хэрэглэх боломжтой:

#### Example – Жишээ

`#Тайлбарыг#нэг нэг#мөрөөр ингэж оруулаарайprint("Hello, World!")`

Or, not quite as intended, you can use a multiline string.

Эсвэл, бүрэн зохиогдоогүй ч гэсэн олон мөртэй мөрийн тэмдэглэлийг ашиглаж болно.

Since Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it:

Python нь хувьсагчид оноогдоогүй мөрийн тэмдэглэлүүдийг алгасхийн тулд олон мөртэй тэмдэглэл (гурвалсан хашилт) нэмж, тайлбараа дотор нь оруулж болно:

#### Example – Жишээ

`"""Олон мөртайлбарингэж бичиж болно"""print("Hello, World!")`

As long as the string is not assigned to a variable, Python will read the code, but then ignore it, and you have made a multiline comment.

Хэрэв мөрийг хувьсагчид оноогоогүй бол Python кодыг уншиж, дараа нь алгасах олон мөрт тайлбар бүтээх боломжтой.

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