ლექცია 01 · I კვირაLecture 01 · Week I
შესავალიIntroduction
Python-ის ისტორია · კავშირი სხვა ენებთან · შესრულების გარემო · სინტაქსი, სტრუქტურა, კომენტარები · რეზერვირებული სიტყვები Python’s history · how it relates to other languages · the runtime · syntax, structure, comments · reserved words
ორიენტირებაOrientation
კურსის რუკა — 15 კვირაCourse map — 15 weeks
- I–IV · საფუძვლებისინტაქსი · ცვლადები და ტიპები · ოპერატორები · ციკლები
- V–VII · ფუნქციები და ტექსტიჩაშენებული ფუნქციები, math, random · საკუთარი ფუნქციები · სტრიქონები
- VIII · შუალედური გამოცდა10 ტესტი + 10 ღია კითხვა = 30 ქულა
- I–IV · FoundationsSyntax · variables and types · operators · loops
- V–VII · Functions and textBuilt-ins, math, random · your own functions · strings
- VIII · Midterm exam10 test questions + 10 open questions = 30 points
- IX–XI · მონაცემებიფაილები · სიები და tuple · სიმრავლე და ლექსიკონი
- XII–XIII · მდგრადობაშეცდომები და try/except · იტერატორები და კონტეინერები
- XIV–XV · პროფესიული ჩვევებიPEP 8 · pypi · მოდულები და პაკეტები · git
- IX–XI · DataFiles · lists and tuples · sets and dictionaries
- XII–XIII · RobustnessErrors and try/except · iterators and containers
- XIV–XV · Professional habitsPEP 8 · PyPI · modules and packages · git
ორგანიზებაOrganisation
როგორ ფასდებაHow it is graded
| კომპონენტიComponent | ქულაPoints |
|---|---|
| 5 პრაქტიკული დავალება (8×5)5 practical assignments (8×5) | 40 |
| შუალედური გამოცდაMidterm exam | 30 |
| დასკვნითი გამოცდა (3×10)Final exam (3×10) | 30 |
| სულTotal | 100 |
სარეკომენდაციო სქემაა — კონკრეტული ზღვრები და წესები დაწესებულების მიხედვით განსხვავდება. This is a suggested scheme — exact thresholds and rules vary by institution.
პრაქტიკული დავალების კრიტერიუმიAssignment criteria
- 3 ქულა — შესრულებულია სრულად, შედეგი მიღებულია
- 2 ქულა — დამოუკიდებლად, დათქმულ დროში
- 3 ქულა — გზა სწორია, მექანიკური შეცდომების გარეშე
- 3 points — completed in full, the intended result achieved
- 2 points — done independently, within the allotted time
- 3 points — correct approach, free of mechanical mistakes
საბაზისოFundamentals
რა არის პროგრამა?What is a program?
ალგორითმი — ნაბიჯების მკაცრი თანმიმდევრობა, რომელიც ამოცანას ჭრის.
პროგრამა — ალგორითმი, ჩაწერილი ენაზე, რომელსაც კომპიუტერი ასრულებს.
An algorithm is a strict sequence of steps that solves a problem.
A program is an algorithm written in a language a computer can execute.
ალგორითმი (ბუნებრივი ენა)The algorithm (plain language)
- ჰკითხე მომხმარებელს ორი რიცხვი
- შეკრიბე ისინი
- დაბეჭდე შედეგი
- Ask the user for two numbers
- Add them together
- Print the result
იგივე — Python-ზეThe same — in Python
a = int(input("პირველი: "))
b = int(input("მეორე: "))
print(a + b)
ისტორიაHistory
საიდან მოვიდა PythonWhere Python came from
- 1989 · შობის არდადეგებიჰოლანდიელი პროგრამისტი Guido van Rossum იწყებს „საშობაო ჰობი-პროექტს“
- 1991 · ვერსია 0.9.0პირველი საჯარო გამოშვება
- 2000 · Python 2.0Unicode, garbage collector
- 2008 · Python 3.0უკუთავსებადობის გატეხვა — სუფთა დასაწყისი
- 2020 · Python 2 გარდაიცვალადღეს მხოლოდ Python 3 არსებობს
- 1989 · Christmas breakDutch programmer Guido van Rossum starts a “Christmas hobby project”
- 1991 · version 0.9.0The first public release
- 2000 · Python 2.0Unicode, garbage collector
- 2008 · Python 3.0Backward compatibility broken — a clean start
- 2020 · Python 2 retiredOnly Python 3 exists today
spam და eggs ცვლადებად — ესეც იმ შოუდანაა.
The name is not about the snakeGuido was watching the British comedy show Monty Python’s Flying Circus. That is also why the official docs are full of variables called spam and eggs — same show.
ენის განვითარებას დღეს PEP-ები მართავს (Python Enhancement Proposal) — საჯარო წინადადებები, რომლებზეც საზოგადოება მსჯელობს. მათგან ყველაზე ცნობილია PEP 8 — კოდის სტილის სტანდარტი (XIV კვირა). The language evolves through PEPs (Python Enhancement Proposals) — public proposals the community debates. The best known is PEP 8, the code style standard (week XIV).
კონტექსტიContext
Python სხვა ენებს შორისPython among other languages
| ენაLanguage | ტიპური სფეროTypical use | რით განსხვავდება Python-ისგანHow it differs from Python |
|---|---|---|
| C / C++ | ოპერაციული სისტემები, თამაშებიOperating systems, games | ბევრად სწრაფი, მაგრამ მეხსიერებას თავად მართავ. Python-ის „ძრავი“ (CPython) სწორედ C-ზეა დაწერილი. Much faster, but you manage memory yourself. Python’s own engine (CPython) is written in C. |
| Java / C# | კორპორაციული აპლიკაციებიEnterprise applications | ტიპები სავალდებულოდ იწერება, კოდი ბევრად გრძელია. მკაცრი, მაგრამ დიდ გუნდში უსაფრთხო. Types must be declared and the code is far longer. Strict, but safer in a large team. |
| JavaScript | ვებ-გვერდები, ბრაუზერიWeb pages, the browser | მსგავსად დინამიკურია. ბრაუზერში მუშაობს, Python — სერვერზე და კომპიუტერზე. Dynamic in a similar way. It runs in the browser; Python runs on servers and desktops. |
| Python | ანალიზი, AI, ავტომატიზაცია, ვები, სკრიპტებიAnalysis, AI, automation, web, scripting | მოკლე და წაკითხვადი. სისწრაფეს ცვლის დაწერის სისწრაფეში. Short and readable. It trades run-time speed for writing speed. |
public class Main {
public static void main(String[] a) {
System.out.println("გამარჯობა");
}
}
print("გამარჯობა")
ეს არაა „უკეთესი/უარესი“ — ეს განსხვავებული პრიორიტეტებია. This is not “better or worse” — these are different priorities.
როგორ მუშაობსHow it works
კომპილაცია თუ ინტერპრეტაცია?Compiled or interpreted?
კომპილირებადი (C, Go)Compiled (C, Go)
- კოდი ერთხელ ითარგმნება მანქანურ ენად
- მიიღება
.exe— დამოუკიდებელი ფაილი - სწრაფია
- ყოველი ცვლილება = ხელახლა კომპილაცია
- The code is translated to machine code once
- You get an
.exe— a standalone file - Fast
- Every change means recompiling
ინტერპრეტირებადი (Python)Interpreted (Python)
- კოდი სრულდება ხაზ-ხაზ, გაშვების მომენტში
- შესრულებას სჭირდება Python დაყენებული
- უფრო ნელია
- შეცვალე და მაშინვე გაუშვი — სწრაფი ექსპერიმენტი
- The code runs line by line, at launch time
- Running it requires Python to be installed
- Slower
- Edit and run immediately — fast experiments
შესრულების გარემოThe runtime
რა ხდება, როცა python hello.py ვწერთWhat happens when you run python hello.py
- წყარო —
hello.py, ჩვეულებრივი ტექსტური ფაილი - თარგმნა ბაიტკოდში — შედეგი ინახება
__pycache__/საქაღალდეში,.pycფაილად - შესრულება — Python-ის ვირტუალური მანქანა (PVM) ბაიტკოდს ასრულებს
- შედეგი — ტერმინალში გამოტანილი ტექსტი
- Source —
hello.py, an ordinary text file - Compilation to bytecode — stored in
__pycache__/as a.pycfile - Execution — the Python Virtual Machine (PVM) runs the bytecode
- Result — text printed in the terminal
.py ფაილი Windows-ზეც მუშაობს და Linux-ზეც — ბაიტკოდი ერთია, PVM კი თითოეულ სისტემაზე ცალკე არსებობს.
Which is whyThe same .py file runs on Windows and Linux alike — the bytecode is identical, and each system has its own PVM.
სინტაქსიSyntax
სამი წესი, რომელიც ყველაფერს განსაზღვრავსThree rules that shape everything
- ერთი ხაზი = ერთი ინსტრუქციაწერტილ-მძიმე (
;) არ გვჭირდება — ხაზის დასასრული თავად ჰყოფს - ბლოკს წანაცვლება ქმნისფიგურული ფრჩხილები
{ }არ არსებობს. სტანდარტი — 4 ჰარე - ორწერტილი ხსნის ბლოკს
if,for,while,def— ყოველთვის მთავრდება:-ით
- One line = one statementNo semicolons needed — the end of the line separates statements
- Indentation creates blocksThere are no curly braces
{ }. The standard is 4 spaces - A colon opens a block
if,for,while,def— always end with:
temperature = 30
if temperature > 25:
print("ცხელა")
print("წყალი დალიე")
print("დასასრული")
ბოლო print ბლოკის გარეთაა — ის ყოველთვის შესრულდება.
The last print is outside the block — it always runs.
სინტაქსიSyntax
წანაცვლება — არა ესთეტიკა, არამედ აზრიIndentation is meaning, not decoration
if 5 > 3:
print("ა")
print("ბ")
ა ბ
if 5 > 3:
print("ა")
print("ბ")
ა ბ
აქ „ბ“ ყოველთვის დაიბეჭდება — პირობის მიუხედავად. Here “ბ” always prints — regardless of the condition.
IndentationError: expected an indented block — ორწერტილის შემდეგ ბლოკი არ დაწერე
TabError — ერთ ფაილში ტაბებიც გამოიყენე და ჰარეებიც
Two classic errors
IndentationError: expected an indented block — no block written after the colon
TabError — tabs and spaces mixed in one file
სტრუქტურაStructure
კომენტარებიComments
ტექსტი, რომელსაც Python უგულებელყოფს. დაწერილია ადამიანისთვის.
Text that Python ignores. It is written for humans.
# ერთხაზიანი კომენტარი — ყველაზე ხშირი
# a single-line comment — the most common kind
price = 100 # კომენტარი ინსტრუქციის შემდეგ / after a statement
"""
მრავალხაზიანი ტექსტი.
ტექნიკურად ესაა სტრიქონი, რომელიც არსად ინახება,
მაგრამ პრაქტიკაში კომენტარად გამოიყენება.
"""
def area(a, b):
"""მართკუთხედის ფართობი. ესაა docstring."""
return a * b
print(area.__doc__)
# x-ს ვუმატებ 1-ს · კარგი: # ინდექსი 1-დან იწყება, რადგან 0 სათაურია
A good comment answers “why”, not “what”
Bad: # add 1 to x · Good: # index starts at 1 because row 0 is the header
ლექსიკაVocabulary
რეზერვირებული სიტყვებიReserved words
ენის „საკუთარი“ სიტყვები — ცვლადის სახელად ვერ გამოიყენებ. სულ 35. Words the language keeps for itself — you cannot use them as variable names. 35 in total.
False None True and as assert async
await break class continue def del elif
else except finally for from global if
import in is lambda nonlocal not or
pass raise return try while with yield
import keyword
print(keyword.kwlist)
print(len(keyword.kwlist))
print(keyword.iskeyword("for"))
class = "IT-101"
# SyntaxError: invalid syntaxVS Code რეზერვირებულ სიტყვებს ავტომატურად აფერადებს — თუ სახელი „შეიფერადა“, ესე იგი დაკავებულია. VS Code colours reserved words automatically — if a name lights up, it is taken.
ლექსიკაVocabulary
იდენტიფიკატორები — სახელების წესებიIdentifiers — naming rules
შეიძლებაAllowed
- ასოები, ციფრები, ქვედა ტირე
_ - იწყება ასოთი ან
_-ით - რეგისტრი მნიშვნელოვანია:
age≠Age
- Letters, digits, underscore
_ - Must start with a letter or
_ - Case matters:
age≠Age
student_name = "ნინო"
_temp = 0
count2 = 15
არ შეიძლებაNot allowed
- ციფრით დაწყება
- ჰარე ან სპეცსიმბოლო
- რეზერვირებული სიტყვა
- Starting with a digit
- Spaces or special characters
- A reserved word
2name = "x" # SyntaxError
my name = "x" # SyntaxError
class = "x" # SyntaxError
snake_case (პატარა ასოებით, ტირეებით). სახელი აზრიანი უნდა იყოს: total_price, არა tp ან x1.
PEP 8 recommendsVariables in snake_case (lowercase with underscores). Names should mean something: total_price, not tp or x1.
პრაქტიკაPractice
პირველი სრული პროგრამაYour first complete program
# პროგრამა ესალმება მომხმარებელს / the program greets the user
# ავტორი / author: სახელი გვარი
print("=" * 30)
print("Python-ის კურსი")
print("=" * 30)
name = input("შენი სახელი: ")
print("გამარჯობა,", name)
print("კარგად მოხვედი!")
============================== Python-ის კურსი ============================== შენი სახელი: ნინო გამარჯობა, ნინო კარგად მოხვედი!
დეტალები — input(), ტიპები, print()-ის პარამეტრები — II კვირაზე.
The details — input(), types, print() parameters — come in week II.
დიაგნოსტიკაTroubleshooting
შეცდომების ორი ჯგუფიTwo families of error
სინტაქსურიSyntax errors
კოდი საერთოდ არ ეშვება. Python ვერ „კითხულობს“ დაწერილს.
The code does not run at all. Python cannot parse what you wrote.
print("გამარჯობა"
# SyntaxError: '(' was never closed
გამოსავალი: მიუთითებულ ხაზს და მის წინა ხაზს დახედე. The fix: look at the reported line and the line before it.
შესრულების დროსRuntime errors
კოდი გაეშვა, მაგრამ შუაში ჩავარდა.
The code started, then failed part-way through.
print(10 / 0)
# ZeroDivisionError: division by zero
ამ ჯგუფის დამუშავებას XII კვირაზე ვისწავლით (try / except).
Handling this family comes in week XII (try / except).
შემაჯამებელიWrap-up
რა უნდა დაგამახსოვრდესWhat to remember
- Python — ინტერპრეტირებადი, დინამიკური, წაკითხვადობაზე ორიენტირებული ენა (1991, Guido van Rossum)
- შესრულება:
.py→ ბაიტკოდი → PVM - ბლოკს წანაცვლება ქმნის (4 ჰარე), ბლოკს
:ხსნის - კომენტარი
#-ით, დოკუმენტაცია —"""docstring""" - 35 რეზერვირებული სიტყვა —
keyword.kwlist - სახელები:
snake_case, ციფრით არ იწყება, რეგისტრი მნიშვნელოვანია
- Python is interpreted, dynamic and readability-focused (1991, Guido van Rossum)
- Execution:
.py→ bytecode → PVM - Indentation creates blocks (4 spaces); a
:opens one - Comments with
#, documentation with"""docstring""" - 35 reserved words —
keyword.kwlist - Names:
snake_case, never start with a digit, case matters
input() და print().
Next — lecture 02Basic types, variables, arithmetic, input() and print().