# SOME DESCRIPTIVE TITLE. # Copyright (C) 2001-2024, Python Software Foundation # This file is distributed under the same license as the Python package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2025-06-19 17:36+0300\n" "PO-Revision-Date: 2024-09-30 23:13+0300\n" "Last-Translator: Panagiotis Skias \n" "Language-Team: PyGreece \n" "Language: el\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Poedit 3.5\n" #: tutorial/controlflow.rst:5 msgid "More Control Flow Tools" msgstr "Περισσότερα εργαλεία Ελέγχου Ροής" #: tutorial/controlflow.rst:7 msgid "" "As well as the :keyword:`while` statement just introduced, Python uses a few " "more that we will encounter in this chapter." msgstr "" "Εκτός από τη πρόταση :keyword:`while` που μόλις εισήχθη, η Python " "χρησιμοποιεί μερικές ακόμη που θα συναντήσουμε σε αυτό το κεφάλαιο." #: tutorial/controlflow.rst:14 msgid ":keyword:`!if` Statements" msgstr "Προτάσεις :keyword:`!if`" #: tutorial/controlflow.rst:16 msgid "" "Perhaps the most well-known statement type is the :keyword:`if` statement. " "For example::" msgstr "" "Ίσως ο πιο γνωστός τύπος statement είναι η πρόταση :keyword:`if`. Για " "παράδειγμα::" #: tutorial/controlflow.rst:19 msgid "" ">>> x = int(input(\"Please enter an integer: \"))\n" "Please enter an integer: 42\n" ">>> if x < 0:\n" "... x = 0\n" "... print('Negative changed to zero')\n" "... elif x == 0:\n" "... print('Zero')\n" "... elif x == 1:\n" "... print('Single')\n" "... else:\n" "... print('More')\n" "...\n" "More" msgstr "" ">>> x = int(input(\"Please enter an integer: \"))\n" "Please enter an integer: 42\n" ">>> if x < 0:\n" "... x = 0\n" "... print('Negative changed to zero')\n" "... elif x == 0:\n" "... print('Zero')\n" "... elif x == 1:\n" "... print('Single')\n" "... else:\n" "... print('More')\n" "...\n" "More" #: tutorial/controlflow.rst:33 msgid "" "There can be zero or more :keyword:`elif` parts, and the :keyword:`else` " "part is optional. The keyword ':keyword:`!elif`' is short for 'else if', " "and is useful to avoid excessive indentation. An :keyword:`!if` ... :" "keyword:`!elif` ... :keyword:`!elif` ... sequence is a substitute for the " "``switch`` or ``case`` statements found in other languages." msgstr "" "Μπορεί να υπάρχουν μηδέν ή περισσότερα μέρη :keyword:`elif` και το τμήμα :" "keyword:`else` είναι προαιρετικό. To keyword ':keyword:`!elif`' είναι " "συντομογραφία του 'else if', και είναι χρήσιμη για να αποφύγετε την " "υπερβολική εσοχή. Μια ακολουθία keyword:`!if` ... :keyword:`!elif` ... :" "keyword:`!elif` ... είναι υποκατάστατο των δηλώσεων ``switch`` ή ``case`` " "που υπάρχουν σε άλλες γλώσσες." #: tutorial/controlflow.rst:39 msgid "" "If you're comparing the same value to several constants, or checking for " "specific types or attributes, you may also find the :keyword:`!match` " "statement useful. For more details see :ref:`tut-match`." msgstr "" "Εάν συγκρίνετε την ίδια τιμή με πολλές σταθερές ή ελέγχετε για " "συγκεκριμένους τύπους ή χαρακτηριστικά, μπορεί επίσης να βρείτε χρήσιμη τη " "δήλωση :keyword:`!match` Για περισσότερες λεπτομέρειες, ανατρέξτε στο :ref:" "`tut-match`." #: tutorial/controlflow.rst:46 msgid ":keyword:`!for` Statements" msgstr "Προτάσεις :keyword:`!for`" #: tutorial/controlflow.rst:51 msgid "" "The :keyword:`for` statement in Python differs a bit from what you may be " "used to in C or Pascal. Rather than always iterating over an arithmetic " "progression of numbers (like in Pascal), or giving the user the ability to " "define both the iteration step and halting condition (as C), Python's :" "keyword:`!for` statement iterates over the items of any sequence (a list or " "a string), in the order that they appear in the sequence. For example (no " "pun intended):" msgstr "" "Η δήλωση :keyword:`for` στην Python διαφέρει λίγο από αυτό που μπορεί να " "έχετε συνηθίσει στη C ή στην Pascal. Αντί να επαναλαμβάνετε πάντα μια " "αριθμητική πρόοδο αριθμών (όπως στη Pascal) ή να δίνετε στον χρήστη τη " "δυνατότητα να ορίσει τόσο το βήμα επανάληψης όσο και τη συνθήκη διακοπής " "(όπως C),η δήλωση της Python :keyword:`!for` επαναλαμβάνεται πάνω από τα " "στοιχεία οποιασδήποτε ακολουθίας (λίστας ή συμβολοσειράς), με τη σειρά που " "εμφανίζονται στην ακολουθία. Για παράδειγμα (χωρίς λογοπαίγνιο)::" #: tutorial/controlflow.rst:63 msgid "" ">>> # Measure some strings:\n" ">>> words = ['cat', 'window', 'defenestrate']\n" ">>> for w in words:\n" "... print(w, len(w))\n" "...\n" "cat 3\n" "window 6\n" "defenestrate 12" msgstr "" ">>> # Measure some strings:\n" ">>> words = ['cat', 'window', 'defenestrate']\n" ">>> for w in words:\n" "... print(w, len(w))\n" "...\n" "cat 3\n" "window 6\n" "defenestrate 12" #: tutorial/controlflow.rst:72 msgid "" "Code that modifies a collection while iterating over that same collection " "can be tricky to get right. Instead, it is usually more straight-forward to " "loop over a copy of the collection or to create a new collection::" msgstr "" "Ο κώδικας που τροποποιεί μια συλλογή ενώ επαναλαμβάνεται πάνω από την ίδια " "συλλογή μπορεί να είναι δύσκολος για να γίνει σωστός. Αντίθετα, είναι " "συνήθως πιο απλό να κάνετε loop πάνω από ένα αντίγραφο συλλογής ή να " "δημιουργήσετε μια νέα συλλογή::" #: tutorial/controlflow.rst:76 msgid "" "# Create a sample collection\n" "users = {'Hans': 'active', 'Éléonore': 'inactive', '景太郎': 'active'}\n" "\n" "# Strategy: Iterate over a copy\n" "for user, status in users.copy().items():\n" " if status == 'inactive':\n" " del users[user]\n" "\n" "# Strategy: Create a new collection\n" "active_users = {}\n" "for user, status in users.items():\n" " if status == 'active':\n" " active_users[user] = status" msgstr "" "# Create a sample collection\n" "users = {'Hans': 'active', 'Éléonore': 'inactive', '景太郎': 'active'}\n" "\n" "# Strategy: Iterate over a copy\n" "for user, status in users.copy().items():\n" " if status == 'inactive':\n" " del users[user]\n" "\n" "# Strategy: Create a new collection\n" "active_users = {}\n" "for user, status in users.items():\n" " if status == 'active':\n" " active_users[user] = status" #: tutorial/controlflow.rst:94 msgid "The :func:`range` Function" msgstr "Η συνάρτηση :func:`range`" #: tutorial/controlflow.rst:96 msgid "" "If you do need to iterate over a sequence of numbers, the built-in function :" "func:`range` comes in handy. It generates arithmetic progressions::" msgstr "" "Εάν χρειάζεται να κάνετε επανάληψη σε μια ακολουθία αριθμών, η ενσωματωμένη " "(built-in) συνάρτηση :func:`range` είναι χρήσιμη. Δημιουργεί αριθμητικές " "προόδους::" #: tutorial/controlflow.rst:99 msgid "" ">>> for i in range(5):\n" "... print(i)\n" "...\n" "0\n" "1\n" "2\n" "3\n" "4" msgstr "" ">>> for i in range(5):\n" "... print(i)\n" "...\n" "0\n" "1\n" "2\n" "3\n" "4" #: tutorial/controlflow.rst:108 msgid "" "The given end point is never part of the generated sequence; ``range(10)`` " "generates 10 values, the legal indices for items of a sequence of length " "10. It is possible to let the range start at another number, or to specify " "a different increment (even negative; sometimes this is called the 'step')::" msgstr "" "Το δεδομένο τελικό σημείο δεν αποτελεί ποτέ μέρος της παραγόμενης " "ακολουθίας· το ``range(10)`` δημιουργεί 10 τιμές, τους δείκτες για στοιχεία " "μιας ακολουθίας μήκους 10. Είναι δυνατόν να αφήσουμε το εύρος να ξεκινά από " "άλλο αριθμό ή για να καθορίσετε μια διαφορετική προσαύξηση (ακόμη και " "αρνητική, μερικές φορές αυτό ονομάζεται 'βήμα')::" #: tutorial/controlflow.rst:113 msgid "" ">>> list(range(5, 10))\n" "[5, 6, 7, 8, 9]\n" "\n" ">>> list(range(0, 10, 3))\n" "[0, 3, 6, 9]\n" "\n" ">>> list(range(-10, -100, -30))\n" "[-10, -40, -70]" msgstr "" ">>> list(range(5, 10))\n" "[5, 6, 7, 8, 9]\n" "\n" ">>> list(range(0, 10, 3))\n" "[0, 3, 6, 9]\n" "\n" ">>> list(range(-10, -100, -30))\n" "[-10, -40, -70]" #: tutorial/controlflow.rst:122 msgid "" "To iterate over the indices of a sequence, you can combine :func:`range` " "and :func:`len` as follows::" msgstr "" "Για να γίνουν iterate οι δείκτες μια ακολουθίας, μπορείτε να συνδυάσετε τις :" "func:`range` και :func:`len` ως εξής::" #: tutorial/controlflow.rst:125 msgid "" ">>> a = ['Mary', 'had', 'a', 'little', 'lamb']\n" ">>> for i in range(len(a)):\n" "... print(i, a[i])\n" "...\n" "0 Mary\n" "1 had\n" "2 a\n" "3 little\n" "4 lamb" msgstr "" ">>> a = ['Mary', 'had', 'a', 'little', 'lamb']\n" ">>> for i in range(len(a)):\n" "... print(i, a[i])\n" "...\n" "0 Mary\n" "1 had\n" "2 a\n" "3 little\n" "4 lamb" #: tutorial/controlflow.rst:135 msgid "" "In most such cases, however, it is convenient to use the :func:`enumerate` " "function, see :ref:`tut-loopidioms`." msgstr "" "Στις περισσότερες τέτοιες περιπτώσεις, ωστόσο, είναι βολικό να " "χρησιμοποιήσετε τη συνάρτηση :func:`enumerate`, δείτε :ref:`tut-loopidioms`." #: tutorial/controlflow.rst:138 msgid "A strange thing happens if you just print a range::" msgstr "Ένα περίεργο πράγμα συμβαίνει αν απλώς εκτυπώσετε ένα range::" #: tutorial/controlflow.rst:140 msgid "" ">>> range(10)\n" "range(0, 10)" msgstr "" ">>> range(10)\n" "range(0, 10)" #: tutorial/controlflow.rst:143 msgid "" "In many ways the object returned by :func:`range` behaves as if it is a " "list, but in fact it isn't. It is an object which returns the successive " "items of the desired sequence when you iterate over it, but it doesn't " "really make the list, thus saving space." msgstr "" "Με πολλούς τρόπους το αντικείμενο που επιστρέφεται από το :func:`range` " "συμπεριφέρεται σαν να είναι μια λίστα, αλλά στην πραγματικότητα δεν είναι. " "Είναι ένα αντικείμενο που επιστρέφει τα διαδοχικά στοιχεία της επιθυμητής " "ακολουθίας όταν κάνετε επανάληψη πάνω του, αλλά δεν μπαίνει πραγματικά στη " "λίστα, εξοικονομώντας έτσι χώρο." #: tutorial/controlflow.rst:148 msgid "" "We say such an object is :term:`iterable`, that is, suitable as a target for " "functions and constructs that expect something from which they can obtain " "successive items until the supply is exhausted. We have seen that the :" "keyword:`for` statement is such a construct, while an example of a function " "that takes an iterable is :func:`sum`::" msgstr "" "Λέμε ότι ένα τέτοιο αντικείμενο είναι :term:`iterable`, δηλαδή, κατάλληλο ως " "στόχος για συναρτήσεις και κατασκευές που περιμένουν κάτι από το οποίο " "μπορούν να λάβουν διαδοχικά στοιχεία μέχρι να εξαντληθεί η προσφορά. Είδαμε " "ότι η δήλωση :keyword:`for` είναι μια τέτοια κατασκευή, ενώ ένα παράδειγμα " "συνάρτησης που παίρνει ένα iterable είναι η :func:`sum`::" #: tutorial/controlflow.rst:154 msgid "" ">>> sum(range(4)) # 0 + 1 + 2 + 3\n" "6" msgstr "" ">>> sum(range(4)) # 0 + 1 + 2 + 3\n" "6" #: tutorial/controlflow.rst:157 msgid "" "Later we will see more functions that return iterables and take iterables as " "arguments. In chapter :ref:`tut-structures`, we will discuss in more detail " "about :func:`list`." msgstr "" "Αργότερα θα δούμε περισσότερες συναρτήσεις που επιστρέφουν iterables και " "λαμβάνουν τους iterables ως ορίσματα. Στο κεφάλαιο :ref:`tut-structures`, " "θα συζητήσουμε λεπτομερέστερα για το :func:`list`." #: tutorial/controlflow.rst:164 msgid ":keyword:`!break` and :keyword:`!continue` Statements" msgstr ":keyword:`!break` και :keyword:`!continue` Προτάσεις" #: tutorial/controlflow.rst:166 msgid "" "The :keyword:`break` statement breaks out of the innermost enclosing :" "keyword:`for` or :keyword:`while` loop::" msgstr "" "Η δήλωση :keyword:`break` ξεφεύγει από τον πιο εσωτερικό βρόχο :keyword:" "`for` ή :keyword:`while`::" #: tutorial/controlflow.rst:169 msgid "" ">>> for n in range(2, 10):\n" "... for x in range(2, n):\n" "... if n % x == 0:\n" "... print(f\"{n} equals {x} * {n//x}\")\n" "... break\n" "...\n" "4 equals 2 * 2\n" "6 equals 2 * 3\n" "8 equals 2 * 4\n" "9 equals 3 * 3" msgstr "" ">>> for n in range(2, 10):\n" "... for x in range(2, n):\n" "... if n % x == 0:\n" "... print(f\"{n} equals {x} * {n//x}\")\n" "... break\n" "...\n" "4 equals 2 * 2\n" "6 equals 2 * 3\n" "8 equals 2 * 4\n" "9 equals 3 * 3" #: tutorial/controlflow.rst:180 msgid "" "The :keyword:`continue` statement continues with the next iteration of the " "loop::" msgstr "" "Η δήλωση :keyword:`continue` συνεχίζεται με την επόμενη επανάληψη του " "βρόχου::" #: tutorial/controlflow.rst:183 msgid "" ">>> for num in range(2, 10):\n" "... if num % 2 == 0:\n" "... print(f\"Found an even number {num}\")\n" "... continue\n" "... print(f\"Found an odd number {num}\")\n" "...\n" "Found an even number 2\n" "Found an odd number 3\n" "Found an even number 4\n" "Found an odd number 5\n" "Found an even number 6\n" "Found an odd number 7\n" "Found an even number 8\n" "Found an odd number 9" msgstr "" ">>> for num in range(2, 10):\n" "... if num % 2 == 0:\n" "... print(f\"Found an even number {num}\")\n" "... continue\n" "... print(f\"Found an odd number {num}\")\n" "...\n" "Found an even number 2\n" "Found an odd number 3\n" "Found an even number 4\n" "Found an odd number 5\n" "Found an even number 6\n" "Found an odd number 7\n" "Found an even number 8\n" "Found an odd number 9" #: tutorial/controlflow.rst:202 msgid ":keyword:`!else` Clauses on Loops" msgstr ":keyword:`!else` Ρήτρες στους βρόχους" #: tutorial/controlflow.rst:204 msgid "" "In a :keyword:`!for` or :keyword:`!while` loop the :keyword:`!break` " "statement may be paired with an :keyword:`!else` clause. If the loop " "finishes without executing the :keyword:`!break`, the :keyword:`!else` " "clause executes." msgstr "" "Σε έναν βρόχο :keyword:`!for` ή :keyword:`!while` η πρόταση :keyword:`!" "break` μπορεί να συνδυαστεί με μια πρόταση :keyword:`!else`. Εάν ο βρόχος " "τελειώσει χωρίς να εκτελεστεί η :keyword:`!break`, εκτελείται ο όρος :" "keyword:`!else`." #: tutorial/controlflow.rst:208 msgid "" "In a :keyword:`for` loop, the :keyword:`!else` clause is executed after the " "loop finishes its final iteration, that is, if no break occurred." msgstr "" "Σε έναν βρόχο :keyword:`for`, η πρόταση :keyword:`!else` εκτελείται αφού ο " "βρόχος ολοκληρώσει στην τελική του επανάληψη, δηλαδή αν δεν σημειωθεί " "διάλειμμα." #: tutorial/controlflow.rst:211 msgid "" "In a :keyword:`while` loop, it's executed after the loop's condition becomes " "false." msgstr "" "Σε έναν βρόχο :keyword:`while`, εκτελείται αφού η συνθήκη του βρόχου είναι " "ψευδής." #: tutorial/controlflow.rst:213 msgid "" "In either kind of loop, the :keyword:`!else` clause is **not** executed if " "the loop was terminated by a :keyword:`break`. Of course, other ways of " "ending the loop early, such as a :keyword:`return` or a raised exception, " "will also skip execution of the :keyword:`else` clause." msgstr "" "Σε οποιοδήποτε είδος βρόχου, η πρόταση :keyword:`!else` **δεν** εκτελείται " "εάν ο βρόχος τερματίστηκε με μια λέξη :keyword:`break`. Φυσικά, άλλοι " "τρόποι για να τερματίσετε νωρίς τον βρόχο, όπως ένα :keyword:`return` ή μια " "αυξημένη εξαίρεση, θα παρακάμψουν επίσης την εκτέλεση της πρότασης :keyword:" "`else`." #: tutorial/controlflow.rst:218 msgid "" "This is exemplified in the following :keyword:`!for` loop, which searches " "for prime numbers::" msgstr "" "Αυτό αποδεικνύεται στον ακόλουθο βρόχο :keyword:`!for`, που αναζητά πρώτους " "αριθμούς::" #: tutorial/controlflow.rst:221 msgid "" ">>> for n in range(2, 10):\n" "... for x in range(2, n):\n" "... if n % x == 0:\n" "... print(n, 'equals', x, '*', n//x)\n" "... break\n" "... else:\n" "... # loop fell through without finding a factor\n" "... print(n, 'is a prime number')\n" "...\n" "2 is a prime number\n" "3 is a prime number\n" "4 equals 2 * 2\n" "5 is a prime number\n" "6 equals 2 * 3\n" "7 is a prime number\n" "8 equals 2 * 4\n" "9 equals 3 * 3" msgstr "" ">>> for n in range(2, 10):\n" "... for x in range(2, n):\n" "... if n % x == 0:\n" "... print(n, 'equals', x, '*', n//x)\n" "... break\n" "... else:\n" "... # loop fell through without finding a factor\n" "... print(n, 'is a prime number')\n" "...\n" "2 is a prime number\n" "3 is a prime number\n" "4 equals 2 * 2\n" "5 is a prime number\n" "6 equals 2 * 3\n" "7 is a prime number\n" "8 equals 2 * 4\n" "9 equals 3 * 3" #: tutorial/controlflow.rst:239 msgid "" "(Yes, this is the correct code. Look closely: the ``else`` clause belongs " "to the ``for`` loop, **not** the ``if`` statement.)" msgstr "" "(Ναι, αυτός είναι ο σωστός κώδικας. Κοιτάξτε προσεκτικά: η πρόταση ``else`` " "ανήκει στον βρόχο ``for``, **όχι** στη δήλωση `if`.)" #: tutorial/controlflow.rst:242 msgid "" "One way to think of the else clause is to imagine it paired with the ``if`` " "inside the loop. As the loop executes, it will run a sequence like if/if/if/" "else. The ``if`` is inside the loop, encountered a number of times. If the " "condition is ever true, a ``break`` will happen. If the condition is never " "true, the ``else`` clause outside the loop will execute." msgstr "" "Ένας τρόπος για να σκεφτούμε την ρήτρα else είναι να τη φανταστούμε σε " "σύζευξη με το ``if`` μέσα στον βρόχο. Καθώς εκτελείται ο βρόχος, θα " "εκτελέσει μια ακολουθία όπως if/if/if/else. Το ``if`` βρίσκεται μέσα στον " "βρόχο, συναντάται πολλές φορές. Εάν η συνθήκη είναι ποτέ αληθής, θα συμβεί " "``break``. Εάν η συνθήκη δεν είναι ποτέ αληθής, θα εκτελεστεί ο όρος " "``else`` εκτός του βρόχου." #: tutorial/controlflow.rst:248 msgid "" "When used with a loop, the ``else`` clause has more in common with the " "``else`` clause of a :keyword:`try` statement than it does with that of " "``if`` statements: a ``try`` statement's ``else`` clause runs when no " "exception occurs, and a loop's ``else`` clause runs when no ``break`` " "occurs. For more on the ``try`` statement and exceptions, see :ref:`tut-" "handling`." msgstr "" "Όταν χρησιμοποιείται με έναν βρόχο, η πρόταση ``else`` έχει περισσότερα " "κοινά με την πρόταση ``else`` μιας πρότασης :keyword:`try` παρά με αυτήν των " "statements ``if`` η πρόταση ``else`` μιας ``try`` εκτελείται όταν δεν " "υπάρχει εξαίρεση, και η πρόταση ``else`` ενός βρόχου εκτελείται όταν δεν " "υπάρχει ``break``. Για περισσότερα με τη δήλωση ``try`` και τις εξαιρέσεις, " "δείτε :ref:`tut-handling`." #: tutorial/controlflow.rst:257 msgid ":keyword:`!pass` Statements" msgstr "Προτάσεις :keyword:`!pass`" #: tutorial/controlflow.rst:259 msgid "" "The :keyword:`pass` statement does nothing. It can be used when a statement " "is required syntactically but the program requires no action. For example::" msgstr "" "Η δήλωση :keyword:`pass` δεν κάνει τίποτα. Μπορεί να χρησιμοποιηθεί όταν " "απαιτείται συντακτικά μια πρόταση, αλλά το πρόγραμμα δεν απαιτεί καμία " "ενέργεια. Για παράδειγμα::" #: tutorial/controlflow.rst:262 msgid "" ">>> while True:\n" "... pass # Busy-wait for keyboard interrupt (Ctrl+C)\n" "..." msgstr "" ">>> while True:\n" "... pass # Busy-wait for keyboard interrupt (Ctrl+C)\n" "..." #: tutorial/controlflow.rst:266 msgid "This is commonly used for creating minimal classes::" msgstr "Αυτό χρησιμοποιείται συνήθως για τη δημιουργία ελάχιστων κλάσεων::" #: tutorial/controlflow.rst:268 msgid "" ">>> class MyEmptyClass:\n" "... pass\n" "..." msgstr "" ">>> class MyEmptyClass:\n" "... pass\n" "..." #: tutorial/controlflow.rst:272 msgid "" "Another place :keyword:`pass` can be used is as a place-holder for a " "function or conditional body when you are working on new code, allowing you " "to keep thinking at a more abstract level. The :keyword:`!pass` is silently " "ignored::" msgstr "" "Ένα άλλο μέρος :keyword:`pass` που μπορεί να χρησιμοποιηθεί είναι ως place-" "holder για μια συνάρτηση ή το σώμα υπό όρους όταν εργάζεστε σε νέο κώδικα, " "επιτρέποντας σας να συνεχίσετε να σκέφτεστε σε ένα πιο αφηρημένο επίπεδο. " "Το :keyword:`!pass` αγνοείται σιωπηλά::" #: tutorial/controlflow.rst:276 msgid "" ">>> def initlog(*args):\n" "... pass # Remember to implement this!\n" "..." msgstr "" ">>> def initlog(*args):\n" "... pass # Remember to implement this!\n" "..." #: tutorial/controlflow.rst:284 msgid ":keyword:`!match` Statements" msgstr "Προτάσεις :keyword:`!match`" #: tutorial/controlflow.rst:286 msgid "" "A :keyword:`match` statement takes an expression and compares its value to " "successive patterns given as one or more case blocks. This is superficially " "similar to a switch statement in C, Java or JavaScript (and many other " "languages), but it's more similar to pattern matching in languages like Rust " "or Haskell. Only the first pattern that matches gets executed and it can " "also extract components (sequence elements or object attributes) from the " "value into variables. If no case matches, none of the branches is executed." msgstr "" "Μια δήλωση :keyword:`match` παίρνει μια έκφραση και συγκρίνει την τιμή της " "με διαδοχικά μοτίβα που δίνονται ως ένα ή περισσότερα μπλοκ πεζών-" "κεφαλαίων. Αυτή είναι επιφανειακά παρόμοια με μια πρόταση switch στην C, " "Java ή JavaScript (και πολλές άλλες γλώσσες), αλλά είναι πιο παρόμοια με την " "αντιστοίχιση προτύπων σε γλώσσες όπως η Rust ή η Haskell. Εκτελείται μόνο το " "πρώτο μοτίβο που ταιριάζει και μπορεί επίσης να εξαγάγει στοιχεία (στοιχεία " "ακολουθίας ή ιδιότητες αντικειμένου) από την τιμή σε μεταβλητές. Εάν καμία " "περίπτωση δεν ταιριάζει, κανένας από τους κλάδους δεν εκτελείται." #: tutorial/controlflow.rst:295 msgid "" "The simplest form compares a subject value against one or more literals::" msgstr "" "Η απλούστερη φόρμα συγκρίνει μια τιμή θέματος με ένα ή περισσότερα literals::" #: tutorial/controlflow.rst:297 msgid "" "def http_error(status):\n" " match status:\n" " case 400:\n" " return \"Bad request\"\n" " case 404:\n" " return \"Not found\"\n" " case 418:\n" " return \"I'm a teapot\"\n" " case _:\n" " return \"Something's wrong with the internet\"" msgstr "" "def http_error(status):\n" " match status:\n" " case 400:\n" " return \"Bad request\"\n" " case 404:\n" " return \"Not found\"\n" " case 418:\n" " return \"I'm a teapot\"\n" " case _:\n" " return \"Something's wrong with the internet\"" #: tutorial/controlflow.rst:308 msgid "" "Note the last block: the \"variable name\" ``_`` acts as a *wildcard* and " "never fails to match." msgstr "" "Σημειώστε το τελευταίο μπλοκ: το \"variable name\" ``_`` λειτουργεί ως " "*μπαλαντέρ* και δεν αποτυγχάνει ποτέ να ταιριάζει." #: tutorial/controlflow.rst:311 msgid "" "You can combine several literals in a single pattern using ``|`` (\"or\")::" msgstr "" "Μπορείτε να συνδυάσετε πολλά γράμματα σε ένα μόνο μοτίβο χρησιμοποιώντας το " "``|`` (\"ή\")::" #: tutorial/controlflow.rst:313 msgid "" "case 401 | 403 | 404:\n" " return \"Not allowed\"" msgstr "" "case 401 | 403 | 404:\n" " return \"Not allowed\"" #: tutorial/controlflow.rst:316 msgid "" "Patterns can look like unpacking assignments, and can be used to bind " "variables::" msgstr "" "Τα μοτίβα μπορεί να μοιάζουν με αναθέσεις unpacking, και μπορούν να " "χρησιμοποιηθούν για τη σύνδεση μεταβλητών::" #: tutorial/controlflow.rst:319 msgid "" "# point is an (x, y) tuple\n" "match point:\n" " case (0, 0):\n" " print(\"Origin\")\n" " case (0, y):\n" " print(f\"Y={y}\")\n" " case (x, 0):\n" " print(f\"X={x}\")\n" " case (x, y):\n" " print(f\"X={x}, Y={y}\")\n" " case _:\n" " raise ValueError(\"Not a point\")" msgstr "" "# point is an (x, y) tuple\n" "match point:\n" " case (0, 0):\n" " print(\"Origin\")\n" " case (0, y):\n" " print(f\"Y={y}\")\n" " case (x, 0):\n" " print(f\"X={x}\")\n" " case (x, y):\n" " print(f\"X={x}, Y={y}\")\n" " case _:\n" " raise ValueError(\"Not a point\")" #: tutorial/controlflow.rst:332 msgid "" "Study that one carefully! The first pattern has two literals, and can be " "thought of as an extension of the literal pattern shown above. But the next " "two patterns combine a literal and a variable, and the variable *binds* a " "value from the subject (``point``). The fourth pattern captures two values, " "which makes it conceptually similar to the unpacking assignment ``(x, y) = " "point``." msgstr "" "Μελετήστε το ένα προσεκτικά! Το πρώτο μοτίβο έχει δύο literals, και μπορεί " "να θεωρηθεί ως επέκταση του literal μοτίβου που φαίνεται παραπάνω. Αλλά τα " "επόμενα δύο μοτίβα συνδυάζουν ένα literal σε μια μεταβλητή, και η μεταβλητή " "*δεσμεύει* μια τιμή από το θέμα (``point``). Το τέταρτο μοτίβο συλλαμβάνει " "δύο τιμές, γεγονός που το κάνει εννοιολογικά παρόμοιο με την ανάθεση " "unpacking ``(x, y) = point``." #: tutorial/controlflow.rst:339 msgid "" "If you are using classes to structure your data you can use the class name " "followed by an argument list resembling a constructor, but with the ability " "to capture attributes into variables::" msgstr "" "Εάν χρησιμοποιείτε κλάσεις για τη δομή των δεδομένων σας, μπορείτε να " "χρησιμοποιήσετε το όνομα της κλάσης ακολουθούμενο από μια λίστα ορισμάτων " "που μοιάζει με έναν κατασκευαστή, αλλά με τη δυνατότητα να συλλαμβάνει " "χαρακτηριστικά σε μεταβλητές::" #: tutorial/controlflow.rst:343 msgid "" "class Point:\n" " def __init__(self, x, y):\n" " self.x = x\n" " self.y = y\n" "\n" "def where_is(point):\n" " match point:\n" " case Point(x=0, y=0):\n" " print(\"Origin\")\n" " case Point(x=0, y=y):\n" " print(f\"Y={y}\")\n" " case Point(x=x, y=0):\n" " print(f\"X={x}\")\n" " case Point():\n" " print(\"Somewhere else\")\n" " case _:\n" " print(\"Not a point\")" msgstr "" "class Point:\n" " def __init__(self, x, y):\n" " self.x = x\n" " self.y = y\n" "\n" "def where_is(point):\n" " match point:\n" " case Point(x=0, y=0):\n" " print(\"Origin\")\n" " case Point(x=0, y=y):\n" " print(f\"Y={y}\")\n" " case Point(x=x, y=0):\n" " print(f\"X={x}\")\n" " case Point():\n" " print(\"Somewhere else\")\n" " case _:\n" " print(\"Not a point\")" #: tutorial/controlflow.rst:361 msgid "" "You can use positional parameters with some builtin classes that provide an " "ordering for their attributes (e.g. dataclasses). You can also define a " "specific position for attributes in patterns by setting the " "``__match_args__`` special attribute in your classes. If it's set to (\"x\", " "\"y\"), the following patterns are all equivalent (and all bind the ``y`` " "attribute to the ``var`` variable)::" msgstr "" "Μπορείτε να χρησιμοποιήσετε παραμέτρους θέσης με ορισμένες ενσωματωμένες " "κλάσεις που παρέχουν μια σειρά για τα χαρακτηριστικά τους (π.χ. κλάσεις " "δεδομένων). Μπορείτε επίσης να ορίσετε μια συγκεκριμένη θέση για " "χαρακτηριστικά σε μοτίβα, ορίζοντας το ειδικό χαρακτηριστικό " "``__match_args__`` στις κλάσεις σας. Εάν έχει οριστεί σε (\"x\", \"y\"), τα " "ακόλουθα μοτίβα είναι όλα ισοδύναμα (και όλα δεσμεύουν το χαρακτηριστικό " "``y`` στη μεταβλητή ``var``)::" #: tutorial/controlflow.rst:367 msgid "" "Point(1, var)\n" "Point(1, y=var)\n" "Point(x=1, y=var)\n" "Point(y=var, x=1)" msgstr "" "Point(1, var)\n" "Point(1, y=var)\n" "Point(x=1, y=var)\n" "Point(y=var, x=1)" #: tutorial/controlflow.rst:372 msgid "" "A recommended way to read patterns is to look at them as an extended form of " "what you would put on the left of an assignment, to understand which " "variables would be set to what. Only the standalone names (like ``var`` " "above) are assigned to by a match statement. Dotted names (like ``foo." "bar``), attribute names (the ``x=`` and ``y=`` above) or class names " "(recognized by the \"(...)\" next to them like ``Point`` above) are never " "assigned to." msgstr "" "Ένας συνιστώμενος τρόπος για να διαβάσετε τα μοτίβα είναι να τα δείτε ως μια " "εκτεταμένη μορφή αυτού που θα βάλετε στα αριστερά μιας ανάθεσης, για να " "κατανοήσετε ποιες μεταβλητές θα οριστούν σε τι. Μόνο τα ανεξάρτητα ονόματα " "(όπως ``var`` παραπάνω) εκχωρούνται από μια δήλωση αντιστοίχισης. Ονόματα με " "κουκκίδες (όπως ``foo.bar``), ονόματα χαρακτηριστικών (τα ``x=`` και ``y=`` " "παραπάνω) ή ονόματα κλάσεων (αναγνωρίζονται από το \"(...)\" που βρίσκεται " "δίπλα όπως το ``Point`` παραπάνω) δεν ανατίθενται ποτέ." #: tutorial/controlflow.rst:379 msgid "" "Patterns can be arbitrarily nested. For example, if we have a short list of " "Points, with ``__match_args__`` added, we could match it like this::" msgstr "" "Τα μοτίβα μπορούν να είναι αυθαίρετα ένθετα. Για παράδειγμα, εάν έχουμε μια " "σύντομη λίστα με πόντους, με προσθήκη ``__match_args__``, θα μπορούσαμε να " "την αντιστοιχίσουμε ως εξής::" #: tutorial/controlflow.rst:382 msgid "" "class Point:\n" " __match_args__ = ('x', 'y')\n" " def __init__(self, x, y):\n" " self.x = x\n" " self.y = y\n" "\n" "match points:\n" " case []:\n" " print(\"No points\")\n" " case [Point(0, 0)]:\n" " print(\"The origin\")\n" " case [Point(x, y)]:\n" " print(f\"Single point {x}, {y}\")\n" " case [Point(0, y1), Point(0, y2)]:\n" " print(f\"Two on the Y axis at {y1}, {y2}\")\n" " case _:\n" " print(\"Something else\")" msgstr "" "class Point:\n" " __match_args__ = ('x', 'y')\n" " def __init__(self, x, y):\n" " self.x = x\n" " self.y = y\n" "\n" "match points:\n" " case []:\n" " print(\"No points\")\n" " case [Point(0, 0)]:\n" " print(\"The origin\")\n" " case [Point(x, y)]:\n" " print(f\"Single point {x}, {y}\")\n" " case [Point(0, y1), Point(0, y2)]:\n" " print(f\"Two on the Y axis at {y1}, {y2}\")\n" " case _:\n" " print(\"Something else\")" #: tutorial/controlflow.rst:400 msgid "" "We can add an ``if`` clause to a pattern, known as a \"guard\". If the " "guard is false, ``match`` goes on to try the next case block. Note that " "value capture happens before the guard is evaluated::" msgstr "" "Μπορούμε να προσθέσουμε μια πρόταση ``if`` σε ένα μοτίβο, γνωστό ως " "\"guard\". Εάν το guard είναι false, το ``match`` συνεχίζει για να " "δοκιμάσει το επόμενο μπλοκ πεζών-κεφαλαίων. Λάβετε υπόψη ότι η σύλληψη της " "τιμής γίνεται πριν ο guard αξιολογηθεί::" #: tutorial/controlflow.rst:404 msgid "" "match point:\n" " case Point(x, y) if x == y:\n" " print(f\"Y=X at {x}\")\n" " case Point(x, y):\n" " print(f\"Not on the diagonal\")" msgstr "" "match point:\n" " case Point(x, y) if x == y:\n" " print(f\"Y=X at {x}\")\n" " case Point(x, y):\n" " print(f\"Not on the diagonal\")" #: tutorial/controlflow.rst:410 msgid "Several other key features of this statement:" msgstr "Πολλά άλλα βασικά χαρακτηριστικά αυτής της δήλωσης:" #: tutorial/controlflow.rst:412 msgid "" "Like unpacking assignments, tuple and list patterns have exactly the same " "meaning and actually match arbitrary sequences. An important exception is " "that they don't match iterators or strings." msgstr "" "Όπως το unpacking αναθέσεων, τα μοτίβα πλειάδας (tuple) και λίστας έχουν " "ακριβώς την ίδια σημασία και ταιριάζουν πραγματικά με αυθαίρετες " "ακολουθίες. Μια σημαντική εξαίρεση είναι ότι δεν ταιριάζουν με iterators ή " "συμβολοσειρές." #: tutorial/controlflow.rst:416 msgid "" "Sequence patterns support extended unpacking: ``[x, y, *rest]`` and ``(x, y, " "*rest)`` work similar to unpacking assignments. The name after ``*`` may " "also be ``_``, so ``(x, y, *_)`` matches a sequence of at least two items " "without binding the remaining items." msgstr "" "Τα μοτίβα ακολουθίας υποστηρίζουν εκτεταμένο unpacking: ``[x, y, *rest]`` " "και ``(x, y, *rest)`` λειτουργεί παρόμοια με το unpacking αναθέσεων. Το " "όνομα μετά το ``*`` μπορεί επίσης να είναι ``_``, οπότε το ``(x, y, *_)`` " "αντιστοιχεί σε μια ακολουθία τουλάχιστον δύο στοιχείων χωρίς να δεσμεύει τα " "υπόλοιπα στοιχεία." #: tutorial/controlflow.rst:421 msgid "" "Mapping patterns: ``{\"bandwidth\": b, \"latency\": l}`` captures the " "``\"bandwidth\"`` and ``\"latency\"`` values from a dictionary. Unlike " "sequence patterns, extra keys are ignored. An unpacking like ``**rest`` is " "also supported. (But ``**_`` would be redundant, so it is not allowed.)" msgstr "" "Μοτίβα αντιστοίχισης: ``{\"bandwidth\": b, \"latency\": l}`` καταγράφει τις " "τιμές ``\"bandwidth\"`` και ``\"latency\"`` από ένα λεξικό. Σε αντίθεση με " "τα μοτίβα ακολουθίας, επιπλέον κλειδιά αγνοούνται. Υποστηρίζεται επίσης το " "unpacking όπως το ``**rest``. (Αλλά το ``**_`` θα ήταν περιττό, επομένως " "δεν επιτρέπεται.)" #: tutorial/controlflow.rst:426 msgid "Subpatterns may be captured using the ``as`` keyword::" msgstr "" "Τα δευτερεύοντα μοτίβα μπορούν να αποτυπωθούν χρησιμοποιώντας το keyword " "``as``::" #: tutorial/controlflow.rst:428 msgid "case (Point(x1, y1), Point(x2, y2) as p2): ..." msgstr "case (Point(x1, y1), Point(x2, y2) as p2): ..." #: tutorial/controlflow.rst:430 msgid "" "will capture the second element of the input as ``p2`` (as long as the input " "is a sequence of two points)" msgstr "" "θα καταγράψει το δεύτερο στοιχείο της εισόδου ως ``p2`` (εφόσον η είσοδος " "είναι μια ακολουθία δύο σημείων)" #: tutorial/controlflow.rst:433 msgid "" "Most literals are compared by equality, however the singletons ``True``, " "``False`` and ``None`` are compared by identity." msgstr "" "Τα περισσότερα literals συγκρίνονται με ισότητα, ωστόσο τα singletons " "``True``, ``False`` και ``None`` συγκρίνονται με ταυτότητα." #: tutorial/controlflow.rst:436 msgid "" "Patterns may use named constants. These must be dotted names to prevent " "them from being interpreted as capture variable::" msgstr "" "Τα μοτίβα μπορούν να χρησιμοποιούν ονομασμένες σταθερές. Αυτά πρέπει να " "είναι ονόματα με κουκκίδες για να μην ερμηνεύονται ως capture μεταβλητή::" #: tutorial/controlflow.rst:439 msgid "" "from enum import Enum\n" "class Color(Enum):\n" " RED = 'red'\n" " GREEN = 'green'\n" " BLUE = 'blue'\n" "\n" "color = Color(input(\"Enter your choice of 'red', 'blue' or 'green': \"))\n" "\n" "match color:\n" " case Color.RED:\n" " print(\"I see red!\")\n" " case Color.GREEN:\n" " print(\"Grass is green\")\n" " case Color.BLUE:\n" " print(\"I'm feeling the blues :(\")" msgstr "" "from enum import Enum\n" "class Color(Enum):\n" " RED = 'red'\n" " GREEN = 'green'\n" " BLUE = 'blue'\n" "\n" "color = Color(input(\"Enter your choice of 'red', 'blue' or 'green': \"))\n" "\n" "match color:\n" " case Color.RED:\n" " print(\"I see red!\")\n" " case Color.GREEN:\n" " print(\"Grass is green\")\n" " case Color.BLUE:\n" " print(\"I'm feeling the blues :(\")" #: tutorial/controlflow.rst:455 msgid "" "For a more detailed explanation and additional examples, you can look into :" "pep:`636` which is written in a tutorial format." msgstr "" "Για πιο λεπτομερή επεξήγηση και πρόσθετα παραδείγματα, μπορείτε να δείτε το :" "pep:`636` το οποίο είναι γραμμένο σε μορφή εκμάθησης." #: tutorial/controlflow.rst:461 msgid "Defining Functions" msgstr "Καθορισμός Συναρτήσεων" #: tutorial/controlflow.rst:463 msgid "" "We can create a function that writes the Fibonacci series to an arbitrary " "boundary::" msgstr "" "Μπορούμε να δημιουργήσουμε μια συνάρτηση που γράφει τη σειρά Fibonacci σε " "ένα αυθαίρετο όριο::" #: tutorial/controlflow.rst:466 msgid "" ">>> def fib(n): # write Fibonacci series less than n\n" "... \"\"\"Print a Fibonacci series less than n.\"\"\"\n" "... a, b = 0, 1\n" "... while a < n:\n" "... print(a, end=' ')\n" "... a, b = b, a+b\n" "... print()\n" "...\n" ">>> # Now call the function we just defined:\n" ">>> fib(2000)\n" "0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597" msgstr "" ">>> def fib(n): # write Fibonacci series less than n\n" "... \"\"\"Print a Fibonacci series less than n.\"\"\"\n" "... a, b = 0, 1\n" "... while a < n:\n" "... print(a, end=' ')\n" "... a, b = b, a+b\n" "... print()\n" "...\n" ">>> # Now call the function we just defined:\n" ">>> fib(2000)\n" "0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597" #: tutorial/controlflow.rst:483 msgid "" "The keyword :keyword:`def` introduces a function *definition*. It must be " "followed by the function name and the parenthesized list of formal " "parameters. The statements that form the body of the function start at the " "next line, and must be indented." msgstr "" "Το keyword :keyword:`def` εισάγει μια συνάρτηση *ορισμός*. Πρέπει να " "ακολουθείται από το όνομα της συνάρτησης και τη λίστα των τυπικών παραμέτρων " "σε παρένθεση. Οι δηλώσεις που σχηματίζουν το σώμα της συνάρτησης ξεκινούν " "από την επόμενη γραμμή και πρέπει να είναι εσοχές." #: tutorial/controlflow.rst:488 msgid "" "The first statement of the function body can optionally be a string literal; " "this string literal is the function's documentation string, or :dfn:" "`docstring`. (More about docstrings can be found in the section :ref:`tut-" "docstrings`.) There are tools which use docstrings to automatically produce " "online or printed documentation, or to let the user interactively browse " "through code; it's good practice to include docstrings in code that you " "write, so make a habit of it." msgstr "" "Η πρώτη δήλωση του σώματος της συνάρτησης μπορεί προαιρετικά να είναι ένα " "literal συμβολοσειράς· αυτό το literal συμβολοσειράς είναι η συμβολοσειρά " "τεκμηρίωσης της συνάρτησης ή :dfn:`docstring`. (Περισσότερα για τα docstring " "μπορείτε να βρείτε στην ενότητα :ref:`tut-docstrings`.) Υπάρχουν εργαλεία " "που χρησιμοποιούν docstrings για την αυτόματη παραγωγή διαδικτυακής ή " "έντυπης τεκμηρίωσης ή για να αφήσουν τον χρήστη να περιηγηθεί διαδραστικά " "στον κώδικα· είναι καλή πρακτική να συμπεριλαμβάνονται docstrings στον " "κώδικα που γράφετε, για αυτό κάντε το συνήθεια." #: tutorial/controlflow.rst:495 msgid "" "The *execution* of a function introduces a new symbol table used for the " "local variables of the function. More precisely, all variable assignments " "in a function store the value in the local symbol table; whereas variable " "references first look in the local symbol table, then in the local symbol " "tables of enclosing functions, then in the global symbol table, and finally " "in the table of built-in names. Thus, global variables and variables of " "enclosing functions cannot be directly assigned a value within a function " "(unless, for global variables, named in a :keyword:`global` statement, or, " "for variables of enclosing functions, named in a :keyword:`nonlocal` " "statement), although they may be referenced." msgstr "" "Η *εκτέλεση* μιας συνάρτησης εισάγει έναν νέο πίνακα συμβόλων που " "χρησιμοποιείται για τις τοπικές μεταβλητές της συνάρτησης. Πιο " "συγκεκριμένα, όλες οι εκχωρήσεις μεταβλητών σε μια συνάρτηση αποθηκεύουν την " "τιμή στον πίνακα τοπικών συμβόλων∙ ενώ οι αναφορές μεταβλητών κοιτάζονται " "πρώτα στον πίνακα τοπικών συμβόλων, στη συνέχεια στους πίνακες τοπικών " "συμβόλων των συναρτήσεων που περικλείουν, μετά στον πίνακα καθολικών " "συμβόλων και, τέλος, στον πίνακα ενσωματωμένων ονομάτων. Έτσι, οι καθολικές " "μεταβλητές και οι μεταβλητές των συναρτήσεων που περικλείουν δεν μπορούν να " "εκχωρηθούν ως μια τιμή μέσα σε μια συνάρτηση (εκτός εάν, για καθολικές " "μεταβλητές, που ονομάζονται σε μια δήλωση :keyword:`global` ή, για " "μεταβλητές συναρτήσεων που περικλείουν, ονομάζονται ως μια δήλωση :keyword:" "`nonlocal`), αν και μπορεί να αναφέρονται." #: tutorial/controlflow.rst:506 msgid "" "The actual parameters (arguments) to a function call are introduced in the " "local symbol table of the called function when it is called; thus, arguments " "are passed using *call by value* (where the *value* is always an object " "*reference*, not the value of the object). [#]_ When a function calls " "another function, or calls itself recursively, a new local symbol table is " "created for that call." msgstr "" "Οι πραγματικές παράμετροι (ορίσματα) σε μια κλήση συνάρτησης εισάγονται στον " "τοπικό πίνακα συμβόλων της καλούμενης συνάρτησης όταν αυτή καλείται· έτσι, " "τα ορίσματα μεταβιβάζονται χρησιμοποιώντας *call by value* (όπου η *value* " "είναι πάντα ένα αντικείμενο *reference*, όχι την τιμή του αντικειμένου). " "[#]_ Όταν μια συνάρτηση καλεί μια άλλη συνάρτηση ή καλεί τον εαυτό της " "αναδρομικά, δημιουργείται ένας νέος πίνακας τοπικών συμβόλων για αυτήν την " "κλήση." #: tutorial/controlflow.rst:513 msgid "" "A function definition associates the function name with the function object " "in the current symbol table. The interpreter recognizes the object pointed " "to by that name as a user-defined function. Other names can also point to " "that same function object and can also be used to access the function::" msgstr "" "Ένας ορισμός συνάρτησης συσχετίζει το όνομα της συνάρτησης με το αντικείμενο " "συνάρτησης στον τρέχοντα πίνακα συμβόλων. Ο διερμηνέας αναγνωρίζει το " "αντικείμενο στο οποίο επισημαίνεται αυτό το όνομα ως συνάρτηση που ορίζεται " "από τον χρήστη. Άλλα ονόματα μπορούν επίσης να δείχνουν το ίδιο αντικείμενο " "συνάρτησης και μπορούν επίσης να χρησιμοποιηθούν για πρόσβαση στη συνάρτηση::" #: tutorial/controlflow.rst:518 msgid "" ">>> fib\n" "\n" ">>> f = fib\n" ">>> f(100)\n" "0 1 1 2 3 5 8 13 21 34 55 89" msgstr "" ">>> fib\n" "\n" ">>> f = fib\n" ">>> f(100)\n" "0 1 1 2 3 5 8 13 21 34 55 89" #: tutorial/controlflow.rst:524 msgid "" "Coming from other languages, you might object that ``fib`` is not a function " "but a procedure since it doesn't return a value. In fact, even functions " "without a :keyword:`return` statement do return a value, albeit a rather " "boring one. This value is called ``None`` (it's a built-in name). Writing " "the value ``None`` is normally suppressed by the interpreter if it would be " "the only value written. You can see it if you really want to using :func:" "`print`::" msgstr "" "Προερχόμενοι από άλλες γλώσσες, μπορεί να αντιταχθείτε ότι το ``fib`` δεν " "είναι μια συνάρτηση αλλά μια διαδικασία, καθώς δεν επιστρέφει μια τιμή. " "Στην πραγματικότητα, ακόμη και συναρτήσεις χωρίς δήλωση :keyword:`return` " "επιστρέφουν μια τιμή, αν και μάλλον βαρετή. Αυτή η τιμή ονομάζεται " "``None``. Η εγγραφή της τιμής ``None`` από τον διερμηνέα, εάν θα ήταν η " "μόνη τιμή που γράφεται. Μπορείτε να το δείτε αν το θέλετε πραγματικά " "χρησιμοποιώντας τη :func:`print`::" #: tutorial/controlflow.rst:531 msgid "" ">>> fib(0)\n" ">>> print(fib(0))\n" "None" msgstr "" ">>> fib(0)\n" ">>> print(fib(0))\n" "None" #: tutorial/controlflow.rst:535 msgid "" "It is simple to write a function that returns a list of the numbers of the " "Fibonacci series, instead of printing it::" msgstr "" "Είναι απλό να γράψετε μια συνάρτηση που επιστρέφει μια λίστα με τους " "αριθμούς της σειράς Fibonacci, αντί να την εκτυπώσετε::" #: tutorial/controlflow.rst:538 msgid "" ">>> def fib2(n): # return Fibonacci series up to n\n" "... \"\"\"Return a list containing the Fibonacci series up to n.\"\"\"\n" "... result = []\n" "... a, b = 0, 1\n" "... while a < n:\n" "... result.append(a) # see below\n" "... a, b = b, a+b\n" "... return result\n" "...\n" ">>> f100 = fib2(100) # call it\n" ">>> f100 # write the result\n" "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]" msgstr "" ">>> def fib2(n): # return Fibonacci series up to n\n" "... \"\"\"Return a list containing the Fibonacci series up to n.\"\"\"\n" "... result = []\n" "... a, b = 0, 1\n" "... while a < n:\n" "... result.append(a) # see below\n" "... a, b = b, a+b\n" "... return result\n" "...\n" ">>> f100 = fib2(100) # call it\n" ">>> f100 # write the result\n" "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]" #: tutorial/controlflow.rst:551 msgid "This example, as usual, demonstrates some new Python features:" msgstr "" "Αυτό το παράδειγμα, ως συνήθως, δείχνει μερικά νέα χαρακτηριστικά Python:" #: tutorial/controlflow.rst:553 msgid "" "The :keyword:`return` statement returns with a value from a function. :" "keyword:`!return` without an expression argument returns ``None``. Falling " "off the end of a function also returns ``None``." msgstr "" "Η δήλωση :keyword:`return` επιστρέφει με μια τιμή από μια συνάρτηση. Το :" "keyword:`!return` χωρίς όρισμα έκφρασης, επιστρέφει το ``None``. Η πτώση του " "τέλους μιας συνάρτησης επιστρέφει επίσης ``None``." #: tutorial/controlflow.rst:557 msgid "" "The statement ``result.append(a)`` calls a *method* of the list object " "``result``. A method is a function that 'belongs' to an object and is named " "``obj.methodname``, where ``obj`` is some object (this may be an " "expression), and ``methodname`` is the name of a method that is defined by " "the object's type. Different types define different methods. Methods of " "different types may have the same name without causing ambiguity. (It is " "possible to define your own object types and methods, using *classes*, see :" "ref:`tut-classes`) The method :meth:`!append` shown in the example is " "defined for list objects; it adds a new element at the end of the list. In " "this example it is equivalent to ``result = result + [a]``, but more " "efficient." msgstr "" "Η δήλωση ``result.append(a)`` καλεί μια *μέθοδο* του αντικειμένου της λίστας " "``result``. Μια μέθοδος είναι μια συνάρτηση που 'ανήκει' σε ένα αντικείμενο " "και ονομάζεται ``obj.methodname``, όπου ``obj`` είναι κάποιο αντικείμενο " "(αυτό μπορεί να είναι μια έκφραση), και το ``methodname`` είναι το όνομα " "μιας μεθόδου που ορίζεται από τον τύπο του αντικειμένου. Διαφορετικοί τύποι " "ορίζουν διαφορετικές μεθόδους. Μέθοδοι διαφορετικών τύπων μπορεί να έχουν " "το ίδιο όνομα χωρίς να προκαλούν ασάφεια. (Είναι δυνατό να ορίσετε τους " "δικούς σας τύπους αντικειμένων και μεθόδους, χρησιμοποιώντας *classes*, " "δείτε :ref:`tut-classes`) Η μέθοδος :meth:`!append` που εμφανίζεται στο " "παράδειγμα ορίζεται για αντικείμενα λίστας· προσθέτει ένα νέο στοιχείο στο " "τέλος της λίστας. Σε αυτό το παράδειγμα είναι ισοδύναμο με ``result = " "result + [a]``, αλλά πιο αποτελεσματικό." #: tutorial/controlflow.rst:572 msgid "More on Defining Functions" msgstr "Περισσότερο για τον Καθορισμό Συναρτήσεων" #: tutorial/controlflow.rst:574 msgid "" "It is also possible to define functions with a variable number of arguments. " "There are three forms, which can be combined." msgstr "" "Είναι επίσης δυνατός ο ορισμός συναρτήσεων με μεταβλητό αριθμό ορισμάτων. " "Υπάρχουν τρεις μορφές, που μπορούν να συνδυαστούν." #: tutorial/controlflow.rst:581 msgid "Default Argument Values" msgstr "Προεπιλεγμένες Τιμές Ορίσματος" #: tutorial/controlflow.rst:583 msgid "" "The most useful form is to specify a default value for one or more " "arguments. This creates a function that can be called with fewer arguments " "than it is defined to allow. For example::" msgstr "" "Η πιο χρήσιμη φόρμα είναι να καθορίσετε μια προεπιλεγμένη τιμή για ένα ή " "περισσότερα ορίσματα. Αυτό δημιουργεί μια συνάρτηση που μπορεί να κληθεί με " "λιγότερα ορίσματα από αυτά που έχει ορίσει ότι επιτρέπει. Για παράδειγμα::" #: tutorial/controlflow.rst:587 msgid "" "def ask_ok(prompt, retries=4, reminder='Please try again!'):\n" " while True:\n" " reply = input(prompt)\n" " if reply in {'y', 'ye', 'yes'}:\n" " return True\n" " if reply in {'n', 'no', 'nop', 'nope'}:\n" " return False\n" " retries = retries - 1\n" " if retries < 0:\n" " raise ValueError('invalid user response')\n" " print(reminder)" msgstr "" "def ask_ok(prompt, retries=4, reminder='Please try again!'):\n" " while True:\n" " reply = input(prompt)\n" " if reply in {'y', 'ye', 'yes'}:\n" " return True\n" " if reply in {'n', 'no', 'nop', 'nope'}:\n" " return False\n" " retries = retries - 1\n" " if retries < 0:\n" " raise ValueError('invalid user response')\n" " print(reminder)" #: tutorial/controlflow.rst:599 msgid "This function can be called in several ways:" msgstr "Αυτή η συνάρτηση μπορεί να κληθεί με διάφορους τρόπους:" #: tutorial/controlflow.rst:601 msgid "" "giving only the mandatory argument: ``ask_ok('Do you really want to quit?')``" msgstr "" "δίνοντας μόνο το υποχρεωτικό όρισμα: ``ask_ok('Do you really want to " "quit?')``" #: tutorial/controlflow.rst:603 msgid "" "giving one of the optional arguments: ``ask_ok('OK to overwrite the file?', " "2)``" msgstr "" "δίνοντας ένα από τα προαιρετικά ορίσματα: ``ask_ok('OK to overwrite the " "file?', 2)``" #: tutorial/controlflow.rst:605 msgid "" "or even giving all arguments: ``ask_ok('OK to overwrite the file?', 2, 'Come " "on, only yes or no!')``" msgstr "" "ή δίνοντας όλα τα ορίσματα: ``ask_ok('OK to overwrite the file?', 2, 'Come " "on, only yes or no!')``" #: tutorial/controlflow.rst:608 msgid "" "This example also introduces the :keyword:`in` keyword. This tests whether " "or not a sequence contains a certain value." msgstr "" "Αυτό το παράδειγμα εισάγει επίσης το keyword :keyword:`in`. Αυτό ελέγχει εάν " "μια ακολουθία περιέχει ή όχι μια συγκεκριμένη τιμή." #: tutorial/controlflow.rst:611 msgid "" "The default values are evaluated at the point of function definition in the " "*defining* scope, so that ::" msgstr "" "Οι προεπιλεγμένες τιμές αξιολογούνται στο σημείο του ορισμού της συνάρτησης " "στο πεδίο που *ορίζεται*, έτσι ώστε ::" #: tutorial/controlflow.rst:614 msgid "" "i = 5\n" "\n" "def f(arg=i):\n" " print(arg)\n" "\n" "i = 6\n" "f()" msgstr "" "i = 5\n" "\n" "def f(arg=i):\n" " print(arg)\n" "\n" "i = 6\n" "f()" #: tutorial/controlflow.rst:622 msgid "will print ``5``." msgstr "θα εκτυπώσει ``5``." #: tutorial/controlflow.rst:624 msgid "" "**Important warning:** The default value is evaluated only once. This makes " "a difference when the default is a mutable object such as a list, " "dictionary, or instances of most classes. For example, the following " "function accumulates the arguments passed to it on subsequent calls::" msgstr "" "**Σημαντική προειδοποίηση:** Η προεπιλεγμένη τιμή αξιολογείται μόνο μία " "φορά. Αυτό κάνει τη διαφορά όταν η προεπιλογή είναι ένα μεταβλητό " "αντικείμενο, όπως μια λίστα, λεξικό ή στιγμιότυπα των περισσότερων κλάσεων. " "Για παράδειγμα, η ακόλουθη συνάρτηση συσσωρεύει τα ορίσματα που διαβάζονται " "σε αυτό σε επόμενες κλήσεις::" #: tutorial/controlflow.rst:629 msgid "" "def f(a, L=[]):\n" " L.append(a)\n" " return L\n" "\n" "print(f(1))\n" "print(f(2))\n" "print(f(3))" msgstr "" "def f(a, L=[]):\n" " L.append(a)\n" " return L\n" "\n" "print(f(1))\n" "print(f(2))\n" "print(f(3))" #: tutorial/controlflow.rst:637 msgid "This will print ::" msgstr "Αυτό θα εκτυπώσει ::" #: tutorial/controlflow.rst:639 msgid "" "[1]\n" "[1, 2]\n" "[1, 2, 3]" msgstr "" "[1]\n" "[1, 2]\n" "[1, 2, 3]" #: tutorial/controlflow.rst:643 msgid "" "If you don't want the default to be shared between subsequent calls, you can " "write the function like this instead::" msgstr "" "Εάν δεν θέλετε να γίνεται κοινή χρήση της προεπιλογής μεταξύ των επόμενων " "κλήσεων, μπορείτε να γράψετε τη συνάρτηση ως εξής::" #: tutorial/controlflow.rst:646 msgid "" "def f(a, L=None):\n" " if L is None:\n" " L = []\n" " L.append(a)\n" " return L" msgstr "" "def f(a, L=None):\n" " if L is None:\n" " L = []\n" " L.append(a)\n" " return L" #: tutorial/controlflow.rst:656 msgid "Keyword Arguments" msgstr "Ορίσματα Keyword" #: tutorial/controlflow.rst:658 msgid "" "Functions can also be called using :term:`keyword arguments ` of the form ``kwarg=value``. For instance, the following " "function::" msgstr "" "Οι συναρτήσεις μπορούν επίσης να κληθούν χρησιμοποιώντας το :term:`keyword " "arguments ` της μορφής ``kwarg=value``. Για παράδειγμα, " "την ακόλουθη συνάρτηση::" #: tutorial/controlflow.rst:661 msgid "" "def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):\n" " print(\"-- This parrot wouldn't\", action, end=' ')\n" " print(\"if you put\", voltage, \"volts through it.\")\n" " print(\"-- Lovely plumage, the\", type)\n" " print(\"-- It's\", state, \"!\")" msgstr "" "def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):\n" " print(\"-- This parrot wouldn't\", action, end=' ')\n" " print(\"if you put\", voltage, \"volts through it.\")\n" " print(\"-- Lovely plumage, the\", type)\n" " print(\"-- It's\", state, \"!\")" #: tutorial/controlflow.rst:667 msgid "" "accepts one required argument (``voltage``) and three optional arguments " "(``state``, ``action``, and ``type``). This function can be called in any " "of the following ways::" msgstr "" "δέχεται ένα απαιτούμενο όρισμα (``voltage``) και τρία προαιρετικά ορίσματα " "(``state``, ``action``, και ``type``). Αυτή η συνάρτηση μπορεί να κληθεί με " "οποιονδήποτε από τους ακόλουθους τρόπους::" #: tutorial/controlflow.rst:671 msgid "" "parrot(1000) # 1 positional " "argument\n" "parrot(voltage=1000) # 1 keyword argument\n" "parrot(voltage=1000000, action='VOOOOOM') # 2 keyword arguments\n" "parrot(action='VOOOOOM', voltage=1000000) # 2 keyword arguments\n" "parrot('a million', 'bereft of life', 'jump') # 3 positional " "arguments\n" "parrot('a thousand', state='pushing up the daisies') # 1 positional, 1 " "keyword" msgstr "" "parrot(1000) # 1 positional " "argument\n" "parrot(voltage=1000) # 1 keyword argument\n" "parrot(voltage=1000000, action='VOOOOOM') # 2 keyword arguments\n" "parrot(action='VOOOOOM', voltage=1000000) # 2 keyword arguments\n" "parrot('a million', 'bereft of life', 'jump') # 3 positional " "arguments\n" "parrot('a thousand', state='pushing up the daisies') # 1 positional, 1 " "keyword" #: tutorial/controlflow.rst:678 msgid "but all the following calls would be invalid::" msgstr "αλλά όλες οι ακόλουθες κλήσεις θα ήταν άκυρες::" #: tutorial/controlflow.rst:680 msgid "" "parrot() # required argument missing\n" "parrot(voltage=5.0, 'dead') # non-keyword argument after a keyword " "argument\n" "parrot(110, voltage=220) # duplicate value for the same argument\n" "parrot(actor='John Cleese') # unknown keyword argument" msgstr "" "parrot() # required argument missing\n" "parrot(voltage=5.0, 'dead') # non-keyword argument after a keyword " "argument\n" "parrot(110, voltage=220) # duplicate value for the same argument\n" "parrot(actor='John Cleese') # unknown keyword argument" #: tutorial/controlflow.rst:685 msgid "" "In a function call, keyword arguments must follow positional arguments. All " "the keyword arguments passed must match one of the arguments accepted by the " "function (e.g. ``actor`` is not a valid argument for the ``parrot`` " "function), and their order is not important. This also includes non-" "optional arguments (e.g. ``parrot(voltage=1000)`` is valid too). No argument " "may receive a value more than once. Here's an example that fails due to this " "restriction::" msgstr "" "Σε μια κλήση συνάρτησης, τα keyword ορίσματα πρέπει να ακολουθούν ορίσματα " "θέσης. Όλα τα keyword ορίσματα που διαβάζονται πρέπει να ταιριάζουν με ένα " "από τα ορίσματα που γίνονται δεκτά από τη συνάρτηση (π.χ. το ``actor`` δεν " "είναι έγκυρο όρισμα για τη συνάρτηση ``parrot``), και η διάταξη τους δεν " "είναι σημαντική. Αυτό περιλαμβάνει επίσης μη προαιρετικά ορίσματα (π.χ. " "``parrot(voltage=1000)`` είναι επίσης έγκυρο). Κανένα όρισμα δεν μπορεί να " "λάβει μια τιμή περισσότερες από μία φορές. Ακολουθεί ένα παράδειγμα που " "αποτυγχάνει λόγω αυτού του περιορισμού::" #: tutorial/controlflow.rst:693 msgid "" ">>> def function(a):\n" "... pass\n" "...\n" ">>> function(0, a=0)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: function() got multiple values for argument 'a'" msgstr "" ">>> def function(a):\n" "... pass\n" "...\n" ">>> function(0, a=0)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: function() got multiple values for argument 'a'" #: tutorial/controlflow.rst:701 msgid "" "When a final formal parameter of the form ``**name`` is present, it receives " "a dictionary (see :ref:`typesmapping`) containing all keyword arguments " "except for those corresponding to a formal parameter. This may be combined " "with a formal parameter of the form ``*name`` (described in the next " "subsection) which receives a :ref:`tuple ` containing the " "positional arguments beyond the formal parameter list. (``*name`` must " "occur before ``**name``.) For example, if we define a function like this::" msgstr "" "Όταν υπάρχει μια τελική επίσημη παράμετρος της μορφής ``**name``, λαμβάνει " "ένα λεξικό (δείτε :ref:`typesmapping`) που περιέχει όλα τα keyword ορίσματα " "εκτός από αυτά που αντιστοιχούν σε μια επίσημη παράμετρο. Αυτό μπορεί να " "συνδυαστεί με μια επίσημη παράμετρος της μορφής ``*name`` (που περιγράφεται " "στην επόμενη υποενότητα) η οποία λαμβάνει ένα :ref:`tuple ` που " "περιέχει τα ορίσματα θέσης πέρα από την επίσημη λίστα παραμέτρων. (Το " "``*name`` πρέπει να εμφανίζεται πριν από το ``**name``.) Για παράδειγμα, αν " "ορίσουμε μια συνάρτηση όπως αυτή::" #: tutorial/controlflow.rst:709 msgid "" "def cheeseshop(kind, *arguments, **keywords):\n" " print(\"-- Do you have any\", kind, \"?\")\n" " print(\"-- I'm sorry, we're all out of\", kind)\n" " for arg in arguments:\n" " print(arg)\n" " print(\"-\" * 40)\n" " for kw in keywords:\n" " print(kw, \":\", keywords[kw])" msgstr "" "def cheeseshop(kind, *arguments, **keywords):\n" " print(\"-- Do you have any\", kind, \"?\")\n" " print(\"-- I'm sorry, we're all out of\", kind)\n" " for arg in arguments:\n" " print(arg)\n" " print(\"-\" * 40)\n" " for kw in keywords:\n" " print(kw, \":\", keywords[kw])" #: tutorial/controlflow.rst:718 msgid "It could be called like this::" msgstr "Μπορεί να καλεστεί κάπως έτσι::" #: tutorial/controlflow.rst:720 msgid "" "cheeseshop(\"Limburger\", \"It's very runny, sir.\",\n" " \"It's really very, VERY runny, sir.\",\n" " shopkeeper=\"Michael Palin\",\n" " client=\"John Cleese\",\n" " sketch=\"Cheese Shop Sketch\")" msgstr "" "cheeseshop(\"Limburger\", \"It's very runny, sir.\",\n" " \"It's really very, VERY runny, sir.\",\n" " shopkeeper=\"Michael Palin\",\n" " client=\"John Cleese\",\n" " sketch=\"Cheese Shop Sketch\")" #: tutorial/controlflow.rst:726 msgid "and of course it would print:" msgstr "και φυσικά θα εκτυπώσει:" #: tutorial/controlflow.rst:728 msgid "" "-- Do you have any Limburger ?\n" "-- I'm sorry, we're all out of Limburger\n" "It's very runny, sir.\n" "It's really very, VERY runny, sir.\n" "----------------------------------------\n" "shopkeeper : Michael Palin\n" "client : John Cleese\n" "sketch : Cheese Shop Sketch" msgstr "" "-- Do you have any Limburger ?\n" "-- I'm sorry, we're all out of Limburger\n" "It's very runny, sir.\n" "It's really very, VERY runny, sir.\n" "----------------------------------------\n" "shopkeeper : Michael Palin\n" "client : John Cleese\n" "sketch : Cheese Shop Sketch" #: tutorial/controlflow.rst:739 msgid "" "Note that the order in which the keyword arguments are printed is guaranteed " "to match the order in which they were provided in the function call." msgstr "" "Λάβετε υπόψη ότι η σειρά με την οποία εκτυπώνονται τα keyword ορίσματα είναι " "εγγυημένη ότι ταιριάζει με τη σειρά με την οποία δόθηκαν στην κλήση της " "συνάρτησης." #: tutorial/controlflow.rst:743 msgid "Special parameters" msgstr "Ειδικές παράμετροι" #: tutorial/controlflow.rst:745 msgid "" "By default, arguments may be passed to a Python function either by position " "or explicitly by keyword. For readability and performance, it makes sense to " "restrict the way arguments can be passed so that a developer need only look " "at the function definition to determine if items are passed by position, by " "position or keyword, or by keyword." msgstr "" "Από προεπιλογή, τα ορίσματα μπορούν να μεταβιβαστούν σε μια συνάρτηση Python " "είτε με βάση τη θέση είτε ρητά με το keyword. Για αναγνωσιμότητα και " "απόδοση, είναι λογικό να περιοριστεί ο τρόπος με τον οποίο μπορούν να " "περάσουν τα ορίσματα, έτσι ώστε ένας προγραμματιστής να μην χρειάζεται να " "κοιτάξει τον ορισμό της συνάρτησης για να προσδιορίσει εάν τα στοιχεία " "μεταβιβάζονται κατά θέση, κατά θέση ή keyword, ή κατά keyword." #: tutorial/controlflow.rst:751 msgid "A function definition may look like:" msgstr "Ένας ορισμός συνάρτησης μπορεί να μοιάζει με αυτό:" #: tutorial/controlflow.rst:753 msgid "" "def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):\n" " ----------- ---------- ----------\n" " | | |\n" " | Positional or keyword |\n" " | - Keyword only\n" " -- Positional only" msgstr "" "def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):\n" " ----------- ---------- ----------\n" " | | |\n" " | Positional or keyword |\n" " | - Keyword only\n" " -- Positional only" #: tutorial/controlflow.rst:762 msgid "" "where ``/`` and ``*`` are optional. If used, these symbols indicate the kind " "of parameter by how the arguments may be passed to the function: positional-" "only, positional-or-keyword, and keyword-only. Keyword parameters are also " "referred to as named parameters." msgstr "" "όπου τα ``/`` και ``*`` είναι προαιρετικά. Εάν χρησιμοποιούνται, αυτά τα " "σύμβολα υποδεικνύουν το είδος της παραμέτρους με τον τρόπο που τα ορίσματα " "μπορούν να μεταβιβαστούν στη συνάρτηση: μόνο θέσης (positional-only), θέσης " "ή keyword (positional-or-keyword), και μόνο keyword (keyword-only). Οι " "keyword παράμετροι αναφέρονται επίσης ως ονομασμένες παράμετροι." #: tutorial/controlflow.rst:769 msgid "Positional-or-Keyword Arguments" msgstr "Παράμετροι Θέσης ή Keyword" #: tutorial/controlflow.rst:771 msgid "" "If ``/`` and ``*`` are not present in the function definition, arguments may " "be passed to a function by position or by keyword." msgstr "" "Εάν τα ``/`` και ``*`` δεν υπάρχουν στον ορισμό της συνάρτησης, τα ορίσματα " "μπορούν να μεταβιβαστούν σε μια συνάρτηση ανά θέση ή κατά keyword." #: tutorial/controlflow.rst:776 msgid "Positional-Only Parameters" msgstr "Παράμετροι Μόνο-Θέσης" #: tutorial/controlflow.rst:778 msgid "" "Looking at this in a bit more detail, it is possible to mark certain " "parameters as *positional-only*. If *positional-only*, the parameters' order " "matters, and the parameters cannot be passed by keyword. Positional-only " "parameters are placed before a ``/`` (forward-slash). The ``/`` is used to " "logically separate the positional-only parameters from the rest of the " "parameters. If there is no ``/`` in the function definition, there are no " "positional-only parameters." msgstr "" "Επανεξετάζοντας αυτό το θέμα λίγο πιο λεπτομερώς, είναι δυνατό να " "επισημάνετε ορισμένες παραμέτρους ως *μόνο θέσης*.Εάν *μόνο θέσης*, η σειρά " "των παραμέτρων έχει σημασία και οι παράμετροι δεν μπορούν να μεταβιβαστούν " "με keyword. Οι παράμετροι μόνο θέσης τοποθετούνται πριν από ένα ``/`` (προς " "τα εμπρός-κάθετος). Το ``/``χρησιμοποιείται για να διαχωρίσει λογικά τις " "παραμέτρους μόνο θέσης από τις υπόλοιπες παραμέτρους. Εάν δεν υπάερχει το ``/" "`` στον ορισμό της συνάρτησης, δεν υπάρχουν παράμετροι μόνο θέσης." #: tutorial/controlflow.rst:786 msgid "" "Parameters following the ``/`` may be *positional-or-keyword* or *keyword-" "only*." msgstr "" "Οι παράμετροι που ακολουθούν το ``/`` μπορεί να είναι *θέσης ή keyword* ή " "*μόνο keyword*." #: tutorial/controlflow.rst:790 msgid "Keyword-Only Arguments" msgstr "Ορίσματα μόνο Keyword" #: tutorial/controlflow.rst:792 msgid "" "To mark parameters as *keyword-only*, indicating the parameters must be " "passed by keyword argument, place an ``*`` in the arguments list just before " "the first *keyword-only* parameter." msgstr "" "Για να επισημάνετε τις παραμέτρους ως *μόνο keyword*, υποδεικνύοντας ότι οι " "παράμετροι πρέπει να περάσουν από το keyword όρισμα, τοποθετήσετε ένα ``*`` " "στη λίστα ορισμάτων ακριβώς πριν από την πρώτη παράμετρο *μόνο keyword*." #: tutorial/controlflow.rst:798 msgid "Function Examples" msgstr "Παραδείγματα Συναρτήσεων" #: tutorial/controlflow.rst:800 msgid "" "Consider the following example function definitions paying close attention " "to the markers ``/`` and ``*``::" msgstr "" "Σκεφτείτε τα ακόλουθα παραδείγματα ορισμών συναρτήσεων δίνοντας ιδιαίτερη " "προσοχή στους δείκτες ``/`` και ``*``::" #: tutorial/controlflow.rst:803 msgid "" ">>> def standard_arg(arg):\n" "... print(arg)\n" "...\n" ">>> def pos_only_arg(arg, /):\n" "... print(arg)\n" "...\n" ">>> def kwd_only_arg(*, arg):\n" "... print(arg)\n" "...\n" ">>> def combined_example(pos_only, /, standard, *, kwd_only):\n" "... print(pos_only, standard, kwd_only)" msgstr "" ">>> def standard_arg(arg):\n" "... print(arg)\n" "...\n" ">>> def pos_only_arg(arg, /):\n" "... print(arg)\n" "...\n" ">>> def kwd_only_arg(*, arg):\n" "... print(arg)\n" "...\n" ">>> def combined_example(pos_only, /, standard, *, kwd_only):\n" "... print(pos_only, standard, kwd_only)" #: tutorial/controlflow.rst:816 msgid "" "The first function definition, ``standard_arg``, the most familiar form, " "places no restrictions on the calling convention and arguments may be passed " "by position or keyword::" msgstr "" "Ο πρώτος ορισμός συνάρτησης, ``standard_arg``, η πιο οικεία μορφή, δεν θέτει " "περιορισμούς στη σύμβαση κλήσης και τα ορίσματα μπορούν να περάσουν από θέση " "ή από keyword::" #: tutorial/controlflow.rst:820 msgid "" ">>> standard_arg(2)\n" "2\n" "\n" ">>> standard_arg(arg=2)\n" "2" msgstr "" ">>> standard_arg(2)\n" "2\n" "\n" ">>> standard_arg(arg=2)\n" "2" #: tutorial/controlflow.rst:826 msgid "" "The second function ``pos_only_arg`` is restricted to only use positional " "parameters as there is a ``/`` in the function definition::" msgstr "" "Η δεύτερη συνάρτηση ``pos_only_arg`` περιορίζεται στη χρήση μόνο παραμέτρων " "θέσης καθώς υπάρχει ένα ``/`` στον ορισμός της συνάρτησης::" #: tutorial/controlflow.rst:829 msgid "" ">>> pos_only_arg(1)\n" "1\n" "\n" ">>> pos_only_arg(arg=1)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: pos_only_arg() got some positional-only arguments passed as " "keyword arguments: 'arg'" msgstr "" ">>> pos_only_arg(1)\n" "1\n" "\n" ">>> pos_only_arg(arg=1)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: pos_only_arg() got some positional-only arguments passed as " "keyword arguments: 'arg'" #: tutorial/controlflow.rst:837 msgid "" "The third function ``kwd_only_arg`` only allows keyword arguments as " "indicated by a ``*`` in the function definition::" msgstr "" "Η τρίτη συνάρτηση ``kwd_only_arg`` επιτρέπει μόνο keyword ορίσματα όπως " "υποδεικνύεται από ένα ``*`` στον ορισμός της συνάρτησης::" #: tutorial/controlflow.rst:840 msgid "" ">>> kwd_only_arg(3)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: kwd_only_arg() takes 0 positional arguments but 1 was given\n" "\n" ">>> kwd_only_arg(arg=3)\n" "3" msgstr "" ">>> kwd_only_arg(3)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: kwd_only_arg() takes 0 positional arguments but 1 was given\n" "\n" ">>> kwd_only_arg(arg=3)\n" "3" #: tutorial/controlflow.rst:848 msgid "" "And the last uses all three calling conventions in the same function " "definition::" msgstr "" "Και το τελευταίο χρησιμοποιεί και τις τρεις συμβάσεις κλήσης στον ίδιο " "ορισμό συνάρτησης::" #: tutorial/controlflow.rst:851 msgid "" ">>> combined_example(1, 2, 3)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: combined_example() takes 2 positional arguments but 3 were given\n" "\n" ">>> combined_example(1, 2, kwd_only=3)\n" "1 2 3\n" "\n" ">>> combined_example(1, standard=2, kwd_only=3)\n" "1 2 3\n" "\n" ">>> combined_example(pos_only=1, standard=2, kwd_only=3)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: combined_example() got some positional-only arguments passed as " "keyword arguments: 'pos_only'" msgstr "" ">>> combined_example(1, 2, 3)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: combined_example() takes 2 positional arguments but 3 were given\n" "\n" ">>> combined_example(1, 2, kwd_only=3)\n" "1 2 3\n" "\n" ">>> combined_example(1, standard=2, kwd_only=3)\n" "1 2 3\n" "\n" ">>> combined_example(pos_only=1, standard=2, kwd_only=3)\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: combined_example() got some positional-only arguments passed as " "keyword arguments: 'pos_only'" #: tutorial/controlflow.rst:868 msgid "" "Finally, consider this function definition which has a potential collision " "between the positional argument ``name`` and ``**kwds`` which has ``name`` " "as a key::" msgstr "" "Τέλος, εξετάστε αυτόν τον ορισμό συνάρτησης που έχει μια πιθανή σύγκρουση " "μεταξύ του ορίσματος θέσης ``name`` και ``**kwds`` που έχει ως κλειδί το " "``name``::" #: tutorial/controlflow.rst:870 msgid "" "def foo(name, **kwds):\n" " return 'name' in kwds" msgstr "" "def foo(name, **kwds):\n" " return 'name' in kwds" #: tutorial/controlflow.rst:873 msgid "" "There is no possible call that will make it return ``True`` as the keyword " "``'name'`` will always bind to the first parameter. For example::" msgstr "" "Δεν υπάρχει καμία πιθανή κλήση που θα την κάνει να επιστρέψει ``True`` καθώς " "το keyword ``'name'`` θα συνδέεται πάντα με την πρώτη παράμετρο. Για " "παράδειγμα::" #: tutorial/controlflow.rst:876 msgid "" ">>> foo(1, **{'name': 2})\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: foo() got multiple values for argument 'name'\n" ">>>" msgstr "" ">>> foo(1, **{'name': 2})\n" "Traceback (most recent call last):\n" " File \"\", line 1, in \n" "TypeError: foo() got multiple values for argument 'name'\n" ">>>" #: tutorial/controlflow.rst:882 msgid "" "But using ``/`` (positional only arguments), it is possible since it allows " "``name`` as a positional argument and ``'name'`` as a key in the keyword " "arguments::" msgstr "" "Αλλά χρησιμοποιώντας ``/`` (ορίσματα μόνο θέσης), είναι δυνατό καθώς " "επιτρέπει το ``name`` ως όρισμα θέσης και το ``'name'`` ως κλειδί στα " "keyword ορίσματα::" #: tutorial/controlflow.rst:884 msgid "" ">>> def foo(name, /, **kwds):\n" "... return 'name' in kwds\n" "...\n" ">>> foo(1, **{'name': 2})\n" "True" msgstr "" ">>> def foo(name, /, **kwds):\n" "... return 'name' in kwds\n" "...\n" ">>> foo(1, **{'name': 2})\n" "True" #: tutorial/controlflow.rst:890 msgid "" "In other words, the names of positional-only parameters can be used in " "``**kwds`` without ambiguity." msgstr "" "Με άλλα λόγια, τα ονόματα των παραμέτρων μόνο θέσης μπορούν να " "χρησιμοποιηθούν σε ``**kwds`` χωρίς ασάφεια." #: tutorial/controlflow.rst:895 msgid "Recap" msgstr "Ανακεφαλαίωση" #: tutorial/controlflow.rst:897 msgid "" "The use case will determine which parameters to use in the function " "definition::" msgstr "" "Η περίπτωση χρήσης θα καθορίσει ποιες παραμέτρους θα χρησιμοποιηθούν στον " "ορισμό της συνάρτησης::" #: tutorial/controlflow.rst:899 msgid "def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):" msgstr "def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):" #: tutorial/controlflow.rst:901 msgid "As guidance:" msgstr "Ως καθοδήγηση:" #: tutorial/controlflow.rst:903 msgid "" "Use positional-only if you want the name of the parameters to not be " "available to the user. This is useful when parameter names have no real " "meaning, if you want to enforce the order of the arguments when the function " "is called or if you need to take some positional parameters and arbitrary " "keywords." msgstr "" "Χρησιμοποιήστε τη θέση μόνο εάν θέλετε το όνομα των παραμέτρων να μην είναι " "διαθέσιμο στο χρήστη. Αυτό είναι χρήσιμο όταν τα ονόματα παραμέτρων δεν " "έχουν πραγματικό νόημα, εάν δεν θέλετε να επιβάλετε τη σειρά των ορισμάτων " "όταν καλείται η συνάρτηση ή εάν πρέπει να ληφθούν ορισμένες παράμετροι θέσης " "και αυθαίρετα keywords." #: tutorial/controlflow.rst:908 msgid "" "Use keyword-only when names have meaning and the function definition is more " "understandable by being explicit with names or you want to prevent users " "relying on the position of the argument being passed." msgstr "" "Χρησιμοποιήστε keyword μόνο όταν τα ονόματα έχουν νόημα και ο ορισμός της " "συνάρτησης είναι πιο κατανοητός όταν είναι ρητός με ονόματα ή θέλετε να " "αποτρέψετε τους χρήστες να βασίζονται στη θέση του επιχειρήματος που " "μεταβιβάζεται." #: tutorial/controlflow.rst:911 msgid "" "For an API, use positional-only to prevent breaking API changes if the " "parameter's name is modified in the future." msgstr "" "Για ένα API, χρησιμοποιήστε το μόνο θέσης για να αποτρέψετε τη διακοπή των " "αλλαγών τους API, εάν το όνομα της παραμέτρου τροποποιηθεί στο μέλλον." #: tutorial/controlflow.rst:917 msgid "Arbitrary Argument Lists" msgstr "Λίστες Αυθαίρετων Ορισμάτων" #: tutorial/controlflow.rst:922 msgid "" "Finally, the least frequently used option is to specify that a function can " "be called with an arbitrary number of arguments. These arguments will be " "wrapped up in a tuple (see :ref:`tut-tuples`). Before the variable number " "of arguments, zero or more normal arguments may occur. ::" msgstr "" "Τέλος, η λιγότερο συχνά χρησιμοποιούμενη επιλογή είναι να ορίσετε ότι μια " "συνάρτηση μπορεί να κληθεί με έναν αυθαίρετο αριθμός ορισμάτων. Αυτά τα " "ορίσματα θα τυλιχθούν σε μια πλειάδα (tuple) (βλ. :ref:`tut-tuples`). Πριν " "από τον μεταβλητό αριθμό ορισμάτων ενδέχεται να προκύψουν μηδέν ή " "περισσότερα κανονικά ορίσματα. ::" #: tutorial/controlflow.rst:927 msgid "" "def write_multiple_items(file, separator, *args):\n" " file.write(separator.join(args))" msgstr "" "def write_multiple_items(file, separator, *args):\n" " file.write(separator.join(args))" #: tutorial/controlflow.rst:931 msgid "" "Normally, these *variadic* arguments will be last in the list of formal " "parameters, because they scoop up all remaining input arguments that are " "passed to the function. Any formal parameters which occur after the " "``*args`` parameter are 'keyword-only' arguments, meaning that they can only " "be used as keywords rather than positional arguments. ::" msgstr "" "Κανονικά, αυτά τα *variadic* ορίσματα θα είναι τελευταία στη λίστα των " "επίσημων παραμέτρων, επειδή συλλέγουν όλα τα υπόλοιπα ορίσματα εισόδου που " "μεταβιβάζονται στη συνάρτηση. Οποιεσδήποτε τυπικές παράμετροι που " "εμφανίζονται μετά την παράμετρο ``*args`` είναι 'μόνο keyword' ορίσματα, που " "σημαίνει ότι μπορούν να χρησιμοποιηθούν μόνο ως λέξεις-κλειδιά και όχι ως " "ορίσματα θέσης. ::" #: tutorial/controlflow.rst:937 msgid "" ">>> def concat(*args, sep=\"/\"):\n" "... return sep.join(args)\n" "...\n" ">>> concat(\"earth\", \"mars\", \"venus\")\n" "'earth/mars/venus'\n" ">>> concat(\"earth\", \"mars\", \"venus\", sep=\".\")\n" "'earth.mars.venus'" msgstr "" ">>> def concat(*args, sep=\"/\"):\n" "... return sep.join(args)\n" "...\n" ">>> concat(\"earth\", \"mars\", \"venus\")\n" "'earth/mars/venus'\n" ">>> concat(\"earth\", \"mars\", \"venus\", sep=\".\")\n" "'earth.mars.venus'" #: tutorial/controlflow.rst:948 msgid "Unpacking Argument Lists" msgstr "Unpacking Λίστες Ορισμάτων" #: tutorial/controlflow.rst:950 msgid "" "The reverse situation occurs when the arguments are already in a list or " "tuple but need to be unpacked for a function call requiring separate " "positional arguments. For instance, the built-in :func:`range` function " "expects separate *start* and *stop* arguments. If they are not available " "separately, write the function call with the ``*``\\ -operator to unpack " "the arguments out of a list or tuple::" msgstr "" "Η αντίστροφη κατάσταση συμβαίνει όταν τα ορίσματα βρίσκονται ήδη σε μια " "λίστα ή πλειάδα (tuple), αλλά πρέπει να αποσυμπιεστούν για μια κλήση " "συνάρτησης που απαιτεί ξεχωριστά ορίσματα θέσης. Για παράδειγμα, η " "ενσωματωμένη (built-in) συνάρτηση :func:`range` αναμένει ξεχωριστά *start* " "και *stop* ορίσματα. Εάν δεν είναι διαθέσιμα ξεχωριστά, γράψτε την κλήση " "συνάρτησης με τον ``*``\\ -τελεστή για να αποσυμπιέσετε τα ορίσματα από μια " "λίστα ή πλειάδα (tuple)::" #: tutorial/controlflow.rst:957 msgid "" ">>> list(range(3, 6)) # normal call with separate arguments\n" "[3, 4, 5]\n" ">>> args = [3, 6]\n" ">>> list(range(*args)) # call with arguments unpacked from a " "list\n" "[3, 4, 5]" msgstr "" ">>> list(range(3, 6)) # normal call with separate arguments\n" "[3, 4, 5]\n" ">>> args = [3, 6]\n" ">>> list(range(*args)) # call with arguments unpacked from a " "list\n" "[3, 4, 5]" #: tutorial/controlflow.rst:966 msgid "" "In the same fashion, dictionaries can deliver keyword arguments with the " "``**``\\ -operator::" msgstr "" "Με τον ίδιο τρόπο, τα λεξικά μπορούν να παραδίδουν keyword ορίσματα με τον " "``**``\\ -τελεστή::" #: tutorial/controlflow.rst:969 msgid "" ">>> def parrot(voltage, state='a stiff', action='voom'):\n" "... print(\"-- This parrot wouldn't\", action, end=' ')\n" "... print(\"if you put\", voltage, \"volts through it.\", end=' ')\n" "... print(\"E's\", state, \"!\")\n" "...\n" ">>> d = {\"voltage\": \"four million\", \"state\": \"bleedin' demised\", " "\"action\": \"VOOM\"}\n" ">>> parrot(**d)\n" "-- This parrot wouldn't VOOM if you put four million volts through it. E's " "bleedin' demised !" msgstr "" ">>> def parrot(voltage, state='a stiff', action='voom'):\n" "... print(\"-- This parrot wouldn't\", action, end=' ')\n" "... print(\"if you put\", voltage, \"volts through it.\", end=' ')\n" "... print(\"E's\", state, \"!\")\n" "...\n" ">>> d = {\"voltage\": \"four million\", \"state\": \"bleedin' demised\", " "\"action\": \"VOOM\"}\n" ">>> parrot(**d)\n" "-- This parrot wouldn't VOOM if you put four million volts through it. E's " "bleedin' demised !" #: tutorial/controlflow.rst:982 msgid "Lambda Expressions" msgstr "Εκφράσεις Lambda" #: tutorial/controlflow.rst:984 msgid "" "Small anonymous functions can be created with the :keyword:`lambda` keyword. " "This function returns the sum of its two arguments: ``lambda a, b: a+b``. " "Lambda functions can be used wherever function objects are required. They " "are syntactically restricted to a single expression. Semantically, they are " "just syntactic sugar for a normal function definition. Like nested function " "definitions, lambda functions can reference variables from the containing " "scope::" msgstr "" "Μπορούν αν δημιουργηθούν μικρές ανώνυμες συναρτήσεις με το keyword :keyword:" "`lambda`. Αυτή η συνάρτηση επιστρέφει το άθροισμα των δύο ορισμάτων της: " "``lambda a, b: a+b``. Οι συναρτήσεις Lambda μπορούν να χρησιμοποιηθούν όπου " "απαιτούνται αντικείμενα συνάρτησης. Περιορίζονται συντακτικά σε μία μόνο " "έκφραση. Σημασιολογικά, είναι απλώς syntactic sugar για έναν ορισμό " "κανονικής συνάρτησης. Όπως οι ορισμοί ένθετων συναρτήσεων, οι συναρτήσεις " "lambda μπορούν να παραπέμπουν σε μεταβλητές από το πεδίο που περιέχει::" #: tutorial/controlflow.rst:992 msgid "" ">>> def make_incrementor(n):\n" "... return lambda x: x + n\n" "...\n" ">>> f = make_incrementor(42)\n" ">>> f(0)\n" "42\n" ">>> f(1)\n" "43" msgstr "" ">>> def make_incrementor(n):\n" "... return lambda x: x + n\n" "...\n" ">>> f = make_incrementor(42)\n" ">>> f(0)\n" "42\n" ">>> f(1)\n" "43" #: tutorial/controlflow.rst:1001 msgid "" "The above example uses a lambda expression to return a function. Another " "use is to pass a small function as an argument. For instance, :meth:`list." "sort` takes a sorting key function *key* which can be a lambda function::" msgstr "" "Το παραπάνω παράδειγμα χρησιμοποιεί μια έκφραση lambda για να επιστρέψει μια " "συνάρτηση. Μια άλλη χρήση είναι η μετάδοση μιας μικρής συνάρτησης ως " "όρισμα. Για παράδειγμα, η :meth:`list.sort` δέχεται μια συνάρτηση " "ταξινόμησης κλειδιού *key* η οποία μπορεί να είναι μια συνάρτηση lambda::" #: tutorial/controlflow.rst:1005 msgid "" ">>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]\n" ">>> pairs.sort(key=lambda pair: pair[1])\n" ">>> pairs\n" "[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]" msgstr "" ">>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]\n" ">>> pairs.sort(key=lambda pair: pair[1])\n" ">>> pairs\n" "[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]" #: tutorial/controlflow.rst:1014 msgid "Documentation Strings" msgstr "Συμβολοσειρές Τεκμηρίωσης" #: tutorial/controlflow.rst:1021 msgid "" "Here are some conventions about the content and formatting of documentation " "strings." msgstr "" "Ακολουθούν ορισμένες συμβάσεις σχετικά με το περιεχόμενο και τη μορφοποίηση " "των συμβολοσειρών τεκμηρίωσης." #: tutorial/controlflow.rst:1024 msgid "" "The first line should always be a short, concise summary of the object's " "purpose. For brevity, it should not explicitly state the object's name or " "type, since these are available by other means (except if the name happens " "to be a verb describing a function's operation). This line should begin " "with a capital letter and end with a period." msgstr "" "Η πρώτη γραμμή πρέπει να είναι πάντα μια σύντομη, συνοπτική περίληψη του " "σκοπού του αντικειμένου. Για συντομία, δεν πρέπει να αναφέρει ρητά το όνομα " "ή τον τύπο του αντικειμένου , καθώς αυτά είναι διαθέσιμα με άλλα μέσα (εκτός " "εάν το όνομα είναι ρήμα που περιγράφει τη λειτουργία της συνάρτησης). Αυτή " "η γραμμή πρέπει να ξεκινά με κεφαλαίο γράμμα και να τελειώνει με τελεία." #: tutorial/controlflow.rst:1030 msgid "" "If there are more lines in the documentation string, the second line should " "be blank, visually separating the summary from the rest of the description. " "The following lines should be one or more paragraphs describing the object's " "calling conventions, its side effects, etc." msgstr "" "Εάν υπάρχουν περισσότερες γραμμές στη συμβολοσειρά τεκμηρίωσης, η δεύτερη " "γραμμή θα πρέπει να είναι κενή, διαχωρίζοντας οπτικά τη σύνοψη από την " "υπόλοιπη περιγραφή. Οι ακόλουθες γραμμές πρέπει να είναι μία ή περισσότερες " "παράγραφοι που περιγράφουν τις συμβάσεις κλήσης του αντικειμένου, τις " "παρενέργειές του κ.λπ.." #: tutorial/controlflow.rst:1035 msgid "" "The Python parser does not strip indentation from multi-line string literals " "in Python, so tools that process documentation have to strip indentation if " "desired. This is done using the following convention. The first non-blank " "line *after* the first line of the string determines the amount of " "indentation for the entire documentation string. (We can't use the first " "line since it is generally adjacent to the string's opening quotes so its " "indentation is not apparent in the string literal.) Whitespace " "\"equivalent\" to this indentation is then stripped from the start of all " "lines of the string. Lines that are indented less should not occur, but if " "they occur all their leading whitespace should be stripped. Equivalence of " "whitespace should be tested after expansion of tabs (to 8 spaces, normally)." msgstr "" "Ο parser της Python δεν αφαιρεί την εσοχή από τα literals της συμβολοσειράς " "πολλών γραμμών στην Python, επομένως τα εργαλεία που επεξεργάζονται την " "τεκμηρίωση πρέπει να αφαιρέσουν την εσοχή εάν είναι επιθυμητό. Αυτό γίνεται " "χρησιμοποιώντας την ακόλουθη σύμβαση. Η πρώτη μη κενή γραμμή *μετά* την " "πρώτη γραμμή της συμβολοσειράς καθορίζει το μέγεθος της εσοχής για ολόκληρη " "τη συμβολοσειρά τεκμηρίωσης. (Δεν μπορούμε να χρησιμοποιήσουμε την πρώτη " "γραμμή αφού είναι γενικά δίπλα στα εισαγωγικά της συμβολοσειράς, επομένως η " "εσοχή της δεν είναι εμφανής στο literal της συμβολοσειράς.) Το κενό διάστημα " "\"ισοδύναμο\" σε αυτήν την εσοχή αφαιρείται στη συνέχεια από την αρχή όλων " "των γραμμών της συμβολοσειράς. Οι γραμμές που έχουν μικρότερη εσοχή δεν θα " "πρέπει να εμφανίζονται, αλλά αν εμφανιστούν θα πρέπει να αφαιρεθεί όλο το " "αρχικό κενό τους. Η ισοδυναμία των κενών διαστημάτων θα πρέπει να ελέγχεται " "μετά την επέκταση των καρτελών (σε 8 κενά, κανονικά)." #: tutorial/controlflow.rst:1047 msgid "Here is an example of a multi-line docstring::" msgstr "Ακολουθεί ένα παράδειγμα ενός πολλαπλών γραμμών docstring::" #: tutorial/controlflow.rst:1049 msgid "" ">>> def my_function():\n" "... \"\"\"Do nothing, but document it.\n" "...\n" "... No, really, it doesn't do anything.\n" "... \"\"\"\n" "... pass\n" "...\n" ">>> print(my_function.__doc__)\n" "Do nothing, but document it.\n" "\n" "No, really, it doesn't do anything." msgstr "" ">>> def my_function():\n" "... \"\"\"Do nothing, but document it.\n" "...\n" "... No, really, it doesn't do anything.\n" "... \"\"\"\n" "... pass\n" "...\n" ">>> print(my_function.__doc__)\n" "Do nothing, but document it.\n" "\n" "No, really, it doesn't do anything." #: tutorial/controlflow.rst:1065 msgid "Function Annotations" msgstr "Annotations Συναρτήσεων" #: tutorial/controlflow.rst:1073 msgid "" ":ref:`Function annotations ` are completely optional metadata " "information about the types used by user-defined functions (see :pep:`3107` " "and :pep:`484` for more information)." msgstr "" "Το :ref:`Function annotations ` είναι εντελώς προαιρετικές " "πληροφορίες μεταδεδομένων σχετικά με τους τύπους χρησιμοποιούνται από " "συναρτήσεις που καθορίζονται από το χρήστη (δείτε :pep:`3107` και :pep:`484` " "για περισσότερες πληροφορίες)." #: tutorial/controlflow.rst:1077 msgid "" ":term:`Annotations ` are stored in the :attr:`!" "__annotations__` attribute of the function as a dictionary and have no " "effect on any other part of the function. Parameter annotations are defined " "by a colon after the parameter name, followed by an expression evaluating to " "the value of the annotation. Return annotations are defined by a literal ``-" ">``, followed by an expression, between the parameter list and the colon " "denoting the end of the :keyword:`def` statement. The following example has " "a required argument, an optional argument, and the return value annotated::" msgstr "" "Το :term:`Annotations ` αποθηκεύονται στο " "χαρακτηριστικό :attr:`!__annotations__` της συνάρτησης ως λεξικό και δεν " "έχουνε καμία επίδραση σε κανένα άλλο μέρος της συνάρτησης. Τα annotations " "των παραμέτρων ορίζονται με άνω και κάτω τελεία μετά το όνομα παραμέτρου, " "ακολουθούμενη από μια έκφραση που αξιολογεί την τιμή του annotation. Τα " "annotations επιστροφής ορίζονται από ένα literal ``->``, ακολουθούμενο από " "μια έκφραση, μεταξύ της λίστας παραμέτρων και της άνω και κάτω τελείας που " "υποδηλώνει το τέλος της δήλωσης :keyword:`def`. Το ακόλουθο παράδειγμα έχει " "ένα απαιτούμενο όρισμα, ένα προαιρετικό όρισμα και την επιστρεφόμενη τιμή σε " "annotations::" #: tutorial/controlflow.rst:1086 msgid "" ">>> def f(ham: str, eggs: str = 'eggs') -> str:\n" "... print(\"Annotations:\", f.__annotations__)\n" "... print(\"Arguments:\", ham, eggs)\n" "... return ham + ' and ' + eggs\n" "...\n" ">>> f('spam')\n" "Annotations: {'ham': , 'return': , 'eggs': }\n" "Arguments: spam eggs\n" "'spam and eggs'" msgstr "" ">>> def f(ham: str, eggs: str = 'eggs') -> str:\n" "... print(\"Annotations:\", f.__annotations__)\n" "... print(\"Arguments:\", ham, eggs)\n" "... return ham + ' and ' + eggs\n" "...\n" ">>> f('spam')\n" "Annotations: {'ham': , 'return': , 'eggs': }\n" "Arguments: spam eggs\n" "'spam and eggs'" #: tutorial/controlflow.rst:1099 msgid "Intermezzo: Coding Style" msgstr "Intermezzo: Στυλ Κώδικα" #: tutorial/controlflow.rst:1104 msgid "" "Now that you are about to write longer, more complex pieces of Python, it is " "a good time to talk about *coding style*. Most languages can be written (or " "more concise, *formatted*) in different styles; some are more readable than " "others. Making it easy for others to read your code is always a good idea, " "and adopting a nice coding style helps tremendously for that." msgstr "" "Τώρα που πρόκειται να γράψετε μεγαλύτερα, και πιο σύνθετα κομμάτια της " "Python, είναι η κατάλληλη στιγμή να μιλήσετε για *στυλ κώδικα*. Οι " "περισσότερες γλώσσες μπορούν να γραφτούν (ή πιο συνοπτικές, " "*μοροφοποιημένες*) σε διαφορετικά στυλ· μερικές είναι πιο ευανάγνωστες από " "άλλες. Το να διευκολύνετε τους άλλους να διαβάσουν τον κώδικα σας είναι " "πάντα μια καλή ιδέα και η υιοθέτηση ενός ωραίου στυλ κώδικα βοηθάει πάρα " "πολύ σε αυτό." #: tutorial/controlflow.rst:1110 msgid "" "For Python, :pep:`8` has emerged as the style guide that most projects " "adhere to; it promotes a very readable and eye-pleasing coding style. Every " "Python developer should read it at some point; here are the most important " "points extracted for you:" msgstr "" "Για την Python, το :pep:`8` έχει αναδειχθεί ως οδηγός στυλ στον οποίο τηρούν " "τα περισσότερα έργα· προωθεί ένα πολύ ευανάγνωστο και ευχάριστο στυλ " "κώδικα. Κάθε προγραμματιστής Python θα πρέπει να το διαβάσει κάποια στιγμή· " "εδώ είναι τα πιο σημαντικό σημεία που εξάγονται για εσάς:" #: tutorial/controlflow.rst:1115 msgid "Use 4-space indentation, and no tabs." msgstr "Χρησιμοποιήστε εσοχή 4 διαστημάτων και όχι tabs." #: tutorial/controlflow.rst:1117 msgid "" "4 spaces are a good compromise between small indentation (allows greater " "nesting depth) and large indentation (easier to read). Tabs introduce " "confusion, and are best left out." msgstr "" "Τα 4 κενά είναι ένας καλός συμβιβασμός μεταξύ της μικρής εσοχής (επιτρέπει " "μεγαλύτερο βάθος εμφώλευσης) και της μεγάλης εσοχής (ευκολότερη στην " "ανάγνωση). Τα tabs δημιουργούν σύγχυση, και είναι καλύτερο να παραμείνουν " "απέξω." #: tutorial/controlflow.rst:1121 msgid "Wrap lines so that they don't exceed 79 characters." msgstr "Τυλίξτε τις γραμμές έτσι ώστε να μην υπερβαίνουν τους 79 χαρακτήρες." #: tutorial/controlflow.rst:1123 msgid "" "This helps users with small displays and makes it possible to have several " "code files side-by-side on larger displays." msgstr "" "Αυτό βοηθά του χρήστες με μικρές οθόνες και καθιστά δυνατή την ύπαρξη πολλών " "αρχείων κώδικα δίπλα-δίπλα σε μεγαλύτερες οθόνες." #: tutorial/controlflow.rst:1126 msgid "" "Use blank lines to separate functions and classes, and larger blocks of code " "inside functions." msgstr "" "Χρησιμοποιείστε κενές γραμμές για να διαχωρίσετε συναρτήσεις και κλάσεις και " "μεγαλύτερα μπλοκ κώδικα μέσα συναρτήσεις." #: tutorial/controlflow.rst:1129 msgid "When possible, put comments on a line of their own." msgstr "Όταν είναι δυνατόν, βάλτε σχόλια σε μια δική τους γραμμή." #: tutorial/controlflow.rst:1131 msgid "Use docstrings." msgstr "Χρησιμοποιήστε docstrings." #: tutorial/controlflow.rst:1133 msgid "" "Use spaces around operators and after commas, but not directly inside " "bracketing constructs: ``a = f(1, 2) + g(3, 4)``." msgstr "" "Χρησιμοποιήστε κενά γύρω από τελεστές και μετά από κόμματα, αλλά όχι " "απευθείας μέσα δε δομές αγκύλων: ``a = f(1, 2) + g(3, 4)``." #: tutorial/controlflow.rst:1136 msgid "" "Name your classes and functions consistently; the convention is to use " "``UpperCamelCase`` for classes and ``lowercase_with_underscores`` for " "functions and methods. Always use ``self`` as the name for the first method " "argument (see :ref:`tut-firstclasses` for more on classes and methods)." msgstr "" "Ονομάστε τις κλάσεις και τις συναρτήσεις σας με συνέπεια· η σύμβαση είναι να " "χρησιμοποιείτε ``UpperCamelCase`` για τις κλάσεις και " "``lowercase_with_underscores`` για τις συναρτήσεις και τις μεθόδους. " "Χρησιμοποιείτε πάντα το ``self`` ως όνομα για το πρώτο όρισμα μεθόδου " "(δείτε :ref:`tut-firstclasses` για περισσότερα σχετικά με τις κλάσεις και " "τις μεθόδους)." #: tutorial/controlflow.rst:1141 msgid "" "Don't use fancy encodings if your code is meant to be used in international " "environments. Python's default, UTF-8, or even plain ASCII work best in any " "case." msgstr "" "Μην χρησιμοποιείτε φανταχτερές κωδικοποιήσεις εάν ο κώδικας σας προορίζεται " "να χρησιμοποιηθεί σε διεθνή περιβάλλοντα. Η προεπιλογή της Python, UTF-8, ή " "ακόμα και το απλό ASCII λειτουργούν καλύτερα σε κάθε περίπτωση." #: tutorial/controlflow.rst:1145 msgid "" "Likewise, don't use non-ASCII characters in identifiers if there is only the " "slightest chance people speaking a different language will read or maintain " "the code." msgstr "" "Ομοίως, μη χρησιμοποιείτε χαρακτήρες που δεν είναι ASCII σε αναγνωριστικά " "εάν υπάρχει μόνο η παραμικρή πιθανότητα οι άνθρωποι που μιλούν διαφορετική " "γλώσσα να διαβάσουν ή να διατηρήσουν τον κώδικα." #: tutorial/controlflow.rst:1151 msgid "Footnotes" msgstr "Υποσημειώσεις" #: tutorial/controlflow.rst:1152 msgid "" "Actually, *call by object reference* would be a better description, since if " "a mutable object is passed, the caller will see any changes the callee makes " "to it (items inserted into a list)." msgstr "" "Στην πραγματικότητα, η *κλήση με αναφορά αντικειμένου* θα ήταν μια καλύτερη " "περιγραφή, καθώς εάν μεταβιβαστεί ένα μεταβλητό αντικείμενο, ο καλών θα δει " "τυχόν αλλαγές που κάνει ο καλών σε αυτό (στοιχεία που εισάγονται σε μια " "λίστα)." #: tutorial/controlflow.rst:48 msgid "statement" msgstr "statement" #: tutorial/controlflow.rst:48 msgid "for" msgstr "for" #: tutorial/controlflow.rst:1016 msgid "documentation strings" msgstr "documentation strings" #: tutorial/controlflow.rst:1016 msgid "docstrings" msgstr "docstrings" #: tutorial/controlflow.rst:1016 msgid "strings, documentation" msgstr "strings, documentation" #: tutorial/controlflow.rst:919 msgid "* (asterisk)" msgstr "* (αστερίσκος)" #: tutorial/controlflow.rst:963 msgid "in function calls" msgstr "in function calls" #: tutorial/controlflow.rst:963 msgid "**" msgstr "**" #: tutorial/controlflow.rst:1068 msgid "function" msgstr "function" #: tutorial/controlflow.rst:1068 msgid "annotations" msgstr "annotations" #: tutorial/controlflow.rst:1068 msgid "->" msgstr "->" #: tutorial/controlflow.rst:1068 msgid "function annotations" msgstr "function annotations" #: tutorial/controlflow.rst:1068 msgid ": (colon)" msgstr ": (colon)" #: tutorial/controlflow.rst:1102 msgid "coding" msgstr "coding" #: tutorial/controlflow.rst:1102 msgid "style" msgstr "style" #~ msgid "" #~ "A :keyword:`!for` or :keyword:`!while` loop can include an :keyword:`!" #~ "else` clause." #~ msgstr "" #~ "Ένας βρόχος :keyword:`!for` ή :keyword:`!while` μπορεί να περιλαμβάνει " #~ "μια πρόταση :keyword:`!else`."