ლექცია 01 · I კვირაLecture 01 · Week I

შესავალიIntroduction

Python-ის ისტორია · კავშირი სხვა ენებთან · შესრულების გარემო · სინტაქსი, სტრუქტურა, კომენტარები · რეზერვირებული სიტყვები Python’s history · how it relates to other languages · the runtime · syntax, structure, comments · reserved words

პირველი ლექცია — მოტივაციაა მთავარი, არა მოცულობა. კურსის მიმოხილვაზე 10 წუთი, ისტორიაზე 10, დანარჩენი პრაქტიკაზე. First lecture — motivation matters more than volume. Ten minutes on the course map, ten on history, the rest hands-on.

ორიენტირება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
ლოგიკაყოველი კვირა წინაზე დგას. გამოტოვებული კვირა შემდეგს ორმაგად ართულებს — განსაკუთრებით IV (ციკლები) და VI (ფუნქციები). The logicEvery week builds on the previous one. A missed week makes the next one twice as hard — especially IV (loops) and VI (functions).

ორგანიზებაOrganisation

როგორ ფასდებაHow it is graded

კომპონენტიComponent ქულაPoints
5 პრაქტიკული დავალება (8×5)5 practical assignments (8×5)40
შუალედური გამოცდაMidterm exam30
დასკვნითი გამოცდა (3×10)Final exam (3×10)30
სულTotal100

სარეკომენდაციო სქემაა — კონკრეტული ზღვრები და წესები დაწესებულების მიხედვით განსხვავდება. 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
ყურადღებათუ ერთ-ერთი კრიტერიუმი 0-ია, მთელი დავალება 0 ქულით ფასდება. CarefulIf any single criterion scores 0, the whole assignment scores 0.
ხაზი გაუსვი: 40 ქულა — ესაა ის, რაც აუდიტორიაში კეთდება. ვინც პრაქტიკულებზე მოდის და აკეთებს, ის თითქმის ვერ ჩაიჭრება. Stress this: 40 points come from work done in the room. Students who show up to the labs and do the work will almost never fail.

საბაზისო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)

  1. ჰკითხე მომხმარებელს ორი რიცხვი
  2. შეკრიბე ისინი
  3. დაბეჭდე შედეგი
  1. Ask the user for two numbers
  2. Add them together
  3. Print the result

იგივე — Python-ზეThe same — in Python

a = int(input("პირველი: "))
b = int(input("მეორე: "))
print(a + b)
რთული ნაწილი რომელია?სინტაქსი ორ კვირაში ისწავლება. ალგორითმული აზროვნება — მთელი სემესტრი. ამიტომ ყოველი ამოცანა ჯერ ქაღალდზე დაშალე ნაბიჯებად. Which part is hard?Syntax takes two weeks. Algorithmic thinking takes the whole semester. So break every problem into steps on paper first.

ისტორია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
სახელი გველისგან არ მოდისGuido ბრიტანულ კომედიურ შოუს „Monty Python's Flying Circus“ უყურებდა. ამიტომაც ოფიციალურ დოკუმენტაციაში ხშირად ნახავ 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
რეალურად Python ორივეს აკეთებსჯერ კოდს გადაიყვანს შუალედურ ბაიტკოდში, შემდეგ ვირტუალური მანქანა ასრულებს მას. Python actually does bothFirst it translates the code into intermediate bytecode, then a virtual machine executes it.

შესრულების გარემოThe runtime

რა ხდება, როცა python hello.py ვწერთWhat happens when you run python hello.py

  1. წყაროhello.py, ჩვეულებრივი ტექსტური ფაილი
  2. თარგმნა ბაიტკოდში — შედეგი ინახება __pycache__/ საქაღალდეში, .pyc ფაილად
  3. შესრულება — Python-ის ვირტუალური მანქანა (PVM) ბაიტკოდს ასრულებს
  4. შედეგი — ტერმინალში გამოტანილი ტექსტი
  1. Sourcehello.py, an ordinary text file
  2. Compilation to bytecode — stored in __pycache__/ as a .pyc file
  3. Execution — the Python Virtual Machine (PVM) runs the bytecode
  4. 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.
__pycache__თუ ეს საქაღალდე გამოგიჩნდა — ეს ნორმაა. წაშალო შეგიძლია, Python ხელახლა შექმნის. ვერსიების კონტროლში (git) მას არასდროს ვამატებთ. __pycache__Seeing this folder appear is normal. You may delete it; Python recreates it. Never add it to version control.
ეს სლაიდი შუალედურის ღია კითხვად ხშირად ხვდება — „აღწერეთ Python-ის პროგრამის შესრულების ეტაპები“. This slide often becomes a midterm open question: “describe the stages of executing a Python program”.

სინტაქსიSyntax

სამი წესი, რომელიც ყველაფერს განსაზღვრავსThree rules that shape everything

  1. ერთი ხაზი = ერთი ინსტრუქციაწერტილ-მძიმე (;) არ გვჭირდება — ხაზის დასასრული თავად ჰყოფს
  2. ბლოკს წანაცვლება ქმნისფიგურული ფრჩხილები { } არ არსებობს. სტანდარტი — 4 ჰარე
  3. ორწერტილი ხსნის ბლოკსif, for, while, def — ყოველთვის მთავრდება :-ით
  1. One line = one statementNo semicolons needed — the end of the line separates statements
  2. Indentation creates blocksThere are no curly braces { }. The standard is 4 spaces
  3. A colon opens a blockif, 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
ცოცხლად აჩვენე ორივე შეცდომა — სტუდენტები მათ ისედაც შეხვდებიან, ჯობია ლექციაზე ნახონ და შიში მოეხსნათ. Demonstrate both live — students will hit them anyway, and seeing them in class removes the fear.

სტრუქტურა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"))
რა მოხდება, თუ სცადავ What happens if you try
class = "IT-101"
# SyntaxError: invalid syntax

VS Code რეზერვირებულ სიტყვებს ავტომატურად აფერადებს — თუ სახელი „შეიფერადა“, ესე იგი დაკავებულია. VS Code colours reserved words automatically — if a name lights up, it is taken.

ლექსიკაVocabulary

იდენტიფიკატორები — სახელების წესებიIdentifiers — naming rules

შეიძლებაAllowed

  • ასოები, ციფრები, ქვედა ტირე _
  • იწყება ასოთი ან _-ით
  • რეგისტრი მნიშვნელოვანია: ageAge
  • Letters, digits, underscore _
  • Must start with a letter or _
  • Case matters: ageAge
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
PEP 8-ის რეკომენდაციაცვლადები — 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).

ოქროს წესიშეცდომის ტექსტი წაიკითხე ბოლოდან — ბოლო ხაზი ამბობს რა მოხდა, ზემოთ კი — სად. Golden ruleRead an error from the bottom up — the last line says what happened, the lines above say where.

შემაჯამებელიWrap-up

რა უნდა დაგამახსოვრდესWhat to remember

სახლში1) დააყენე გარემო (იხ. ლექცია 00). 2) დაწერე პროგრამა, რომელიც შენს სახელს, ჯგუფსა და საყვარელ რიცხვს ბეჭდავს. 3) განზრახ დაუშვი 3 სხვადასხვა შეცდომა და ჩაინიშნე მათი ტექსტი. At home1) Set up the environment (see lecture 00). 2) Write a program that prints your name, your group and your favourite number. 3) Deliberately make three different errors and write down their messages.
შემდეგი — ლექცია 02საბაზისო ტიპები, ცვლადები, არითმეტიკა, input() და print(). Next — lecture 02Basic types, variables, arithmetic, input() and print().