Docstring (Sənədləşmə Sətirləri)
Nə Üçündür?
• Koddakı funksiyanın, sinifin və ya modulun nə etdiyini izah edir.
• Kodu oxuyanlar üçün aydınlıq yaradır, xüsusilə komanda ilə işləyərkən və ya böyük layihələrdə.
• Kodun saxlanması, başa düşülməsi və yenilənməsi üçün çox faydalıdır.
Harada İstifadə Olunur?
• Funksiya, class(sinif), modul və ya skriptin ən başında yerləşir.
• Funksiyanın məqsədini, qəbul etdiyi dəyərləri, qaytardığı nəticəni və xüsusi halları izah edir.
Quruluşu və Qaydaları:
• Adətən qısa bir təsvirlə başlayır.
• İstəyə görə bölmələr əlavə olunur: Parametrlər, Qaytardığı dəyər, Xətalar, Nümunələr.
• Müxtəlif standart stillər var (məsələn: Google stili, NumPy stili və s.).
Nəyə Görə Vacibdir?
• Avtomatik sənədləşmə vasitələri (məsələn, Sphinx) docstring-ləri istifadə edir.
• Kod redaktorları və IDE-lər docstring-ləri avtomatik olaraq göstərə bilir.
• Yeni proqramçılar və ya komanda üzvləri üçün çox faydalıdır.
⸻
Annotation-lar (Tip Göstərişləri)
Nə Üçündür?
• Funksiyaların gözlədiyi və qaytardığı məlumat tiplərini göstərir.
• Kodun daha aydın və oxunaqlı olmasına kömək edir.
Əsas Üstünlükləri:
• Kodun məntiqini başa düşmək asanlaşır, xüsusilə mürəkkəb və ya uzun kodlarda.
• Statik analiz alətləri (məsələn, mypy) potensial səhvləri aşkar edə bilər.
• Kod redaktorları daha dəqiq avtomatik tamamlamalar təklif edir.
• Proqramlaşdırma vərdişlərini yaxşılaşdırır, səhvləri azaldır.
Necə İstifadə Olunur?
• Funksiya parametrlərinə və qaytardığı nəticəyə tip göstərişi əlavə olunur.
• Dəyişənlərə də tip göstərmək mümkündür (məsələn, ədəd, sətr, siyahı və s.).
Diqqətəlayiq Nöqtələr:
• Python dinamik tipli dildir — yəni bu göstərişlər icra zamanı məcburi deyil.
• Annotation-lar seçimlidir, lakin tövsiyə olunur.
• Mürəkkəb tiplərlə də işləyə bilər (məsələn: siyahıların içində ədədlər, fərqli tiplərin birləşməsi və s.).
=======
Docstrings (Documentation Strings)
Purpose:
• Help describe what your code is doing.
• Act as in-line documentation for anyone reading or using the code.
• Make your code easier to understand and maintain.
Where They Are Used:
• Inside functions, classes, modules, and even at the start of a script.
• They should explain the purpose, inputs, outputs, and any important behavior or edge cases.
Structure & Conventions:
• Usually start with a short description of what the object does.
• Can include sections like Parameters, Returns, Raises, and Examples.
• There are popular styles such as Google, NumPy, and reStructuredText (RST) that help keep docstrings consistent.
Why They Matter:
• Tools like documentation generators (e.g., Sphinx) use docstrings to create external documentation.
• IDEs and help systems can show docstrings when hovering over functions or using autocomplete.
• Great for teaching, onboarding new developers, and debugging.
⸻
Annotations (Type Hints)
Purpose:
• Indicate what kind of data is expected or returned in functions and variables.
• Add clarity to the code, especially in complex or collaborative projects.
Key Benefits:
• Make code more self-explanatory without needing to run it.
• Help static analysis tools detect bugs early (e.g., type mismatches).
• Improve auto-completion and intelligent suggestions in IDEs.
• Encourage better programming practices and reduce errors.
How They’re Used:
• You can annotate both function arguments and return types.
• Also used with variables to indicate their intended type.
Important Notes:
• Python is still dynamically typed — annotations are not enforced during execution.
• They’re optional, but highly recommended in large or shared codebases.
• You can use complex types like lists of specific items, custom classes, or even unions of types.
#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
Sur cette page du site, vous pouvez voir la vidéo en ligne Python docstring & annotations | metadata __doc__ & __annnotations__ | docstring styles durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur KODY•AZ 01 avril 2025, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 85 fois et il a aimé 15 téléspectateurs. Bon visionnage!