Execute Python Syntax – Python Синтакс Хэрэгжүүлэх  #

As we learned in the previous page, Python syntax can be executed by writing directly in the Command Line:

Бидний өмнөх хуудсанд сурсан, Шууд Команд Мөр дээр Python синтакс бичиж хэрэглэсэн:   

> print("Hello, World!")
Hello, World!

Or by creating a python file on the server, using the .py file extension, and running it in the Command Line:

Эсвэл серверт python файлыг үүсгэж, .py файл өргөтгөл ашиглаж, 

C:\Users\Your Name>python myfile.py

Python Indentation – Python Догол мөр #

Indentation refers to the spaces at the beginning of a code line.

Python-д мөрийн эхэнд байгаа хоосон зайг “догол мөр” гэж нэрлэдэг.

Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.

Бусад програмчлалын хэлнүүдэд догол мөр нь зөвхөн уншихад хялбар байдлыг хангах зориулалттай байдаг бол, Python-д догол мөр маш чухал үүрэгтэй.

Python uses indentation to indicate a block of code.

Python блок кодыг илэрхийлэхийн тулд догол мөрийг ашигладаг.

 

Example – Жишээ #

if 5 > 2:
print("Five is greater than two!")

Python will give you an error if you skip the indentation:

Догол мөрийг алгасвал Python алдаа өгнө:

Example – Жишээ #

Syntax Error: – Өгүүлбэр зүйн Алдаа

if 5 > 2:
print("Five is greater than two!")

The number of spaces is up to you as a programmer, the most common use is four, but it has to be at least one.

Догол мөрийн зайны тоог программистын хувьд өөрөө шийднэ, хамгийн түгээмэл ашиглагддаг нь дөрөв, гэхдээ нэгээс доошгүй байх ёстой.

Example – Жишээ #

if 5 > 2:
 print("Five is greater than two!")
if 5 > 2:
        print("Five is greater than two!")

You have to use the same number of spaces in the same block of code, otherwise Python will give you an error:

Нэг блок код ижил тооны догол мөр ашиглах ёстой, эс бөгөөс Python алдаа өгнө.

Example – Жишээ #

Syntax Error: – Өгүүлбэр зүйн алдаа:

if 5 > 2:
 print("Five is greater than two!")
        print("Five is greater than two!")

Python Variables – Python Хувьсагчууд #

In Python, variables are created when you assign a value to it:

Python-д, хувьсагчууд утга оноох үед үүсдэг:

Example – Жишээ #

Variables in Python:

Python дахь хувьсагчид:

x = 5
y = "Hello, World!"

Python has no command for declaring a variable.

Python-д хувьсагчийг зарлах команд байхгүй.

You will learn more about variables in the Python Variables chapter.

Та Python хувьсагчдын талаар илүү ихийг “Python Хувьсагчууд” бүлэгт мэдэх болно.

Comments – Тайлбар #

Python has commenting capability for the purpose of in-code documentation.

Python кодуудад тайлбар хийх боломжтой.

Comments start with a #, and Python will render the rest of the line as a comment:

Тайлбарууд # тэмдэгээр эхэлдэг бөгөөд Python тэрхүү мөрийг тайлбар гэж үзнэ:

Example – Жишээ

Comments in Python:

Python дахь тайлбар

#This is a comment.
print("Hello, World!")

Powered by BetterDocs

Leave a Reply