COLON (:) usage in Python | iki nöqtə (qoşa nöqtə) Python kodunda | Ən çox edilən səhv #kody_az
Dərs haqqında
Python-da iki nöqtə, if, elif, else, for, while, try, except, finally, with, def, class və match-case kimi strukturların sonunda yazılır və bu, indentasiya (boşluqla başlayan) bir kod blokunun başladığını bildirir.
Slicing (kəsim) əməliyyatları
Sətirlər, siyahılar və oxşar ardıcıllıqlardan müəyyən hissələri almaq üçün istifadə olunur. İki nöqtə başlanğıc, son və addım dəyərlərini ayırmaq üçün tətbiq edilir. İki nöqtə bir neçə şəkildə istifadə oluna bilər: yalnız başlanğıc-son, yalnız addım, və ya hər üçü birlikdə.
Lambda ifadələri
Lambda funksiyalarında iki nöqtə, parametrlərlə əməliyyat hissəsini ayırmaq üçün istifadə olunur. Yəni parametrlər bitir, iki nöqtədən sonra isə hesablanan ifadə gəlir.
Walrus operatoru (:=)
Walrus operatoru iki nöqtə və bərabərlik işarəsindən ibarətdir (:=). Bu operator dəyişkənə dəyər təyin etməyi və eyni anda həmin dəyəri yoxlamağı mümkün edir. Ən çox if və while şərt bloklarında istifadə olunur. Beləliklə, funksiyanı və ya ifadəni iki dəfə yazmadan həm təyin, həm yoxlama həyata keçirilir.
========
In Python, the colon is used at the end of structures such as if, elif, else, for, while, try, except, finally, with, def, class, and match-case.
This indicates the beginning of an indented code block.
Slicing operations
Slicing is used to extract specific parts of strings, lists, and similar sequences. The colon is used to separate the start, stop, and step values. It can be used in various ways: start-stop only, step only, or all three together.
Lambda expressions
In lambda functions, the colon is used to separate the parameters from the expression. The parameters end before the colon, and the expression to be evaluated comes after it.
Walrus operator (:=)
The walrus operator consists of a colon and an equals sign (:=). It allows assigning a value to a variable and checking it at the same time. It is most commonly used in if and while statements. This way, a function or expression does not need to be written twice — both assignment and evaluation happen in a single step.
#python #kody_az #kodyaz #viral #fleet #jetbrains #pycharm #oop #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #azərbaycan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz