Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

3.2 Μέθοδοι πίνακα στην Python

Η Python διαθέτει μια σειρά ενσωματωμένων μεθόδων που μπορείτε να χρησιμοποιήσετε σε λίστες/πίνακες. Εδώ είναι μερικές από τις πιο κοινές μεθόδους για λίστες:

  1. append(): Προσθέτει ένα στοιχείο στο τέλος της λίστας.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana']
fruits.append('cherry')
print(fruits) # Εμφανίζει: ['apple', 'banana', 'cherry']
fruits = ['apple', 'banana'] fruits.append('cherry') print(fruits) # Εμφανίζει: ['apple', 'banana', 'cherry']
fruits = ['apple', 'banana']
fruits.append('cherry')
print(fruits)  # Εμφανίζει: ['apple', 'banana', 'cherry']
  1. extend(): Προσθέτει πολλαπλά στοιχεία στο τέλος της λίστας.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana']
more_fruits = ['cherry', 'orange']
fruits.extend(more_fruits)
print(fruits) # Εμφανίζει: ['apple', 'banana', 'cherry', 'orange']
fruits = ['apple', 'banana'] more_fruits = ['cherry', 'orange'] fruits.extend(more_fruits) print(fruits) # Εμφανίζει: ['apple', 'banana', 'cherry', 'orange']
fruits = ['apple', 'banana']
more_fruits = ['cherry', 'orange']
fruits.extend(more_fruits)
print(fruits)  # Εμφανίζει: ['apple', 'banana', 'cherry', 'orange']
  1. insert(): Εισάγει ένα στοιχείο σε μια καθορισμένη θέση της λίστας.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana']
fruits.insert(1, 'cherry')
print(fruits) # Εμφανίζει: ['apple', 'cherry', 'banana']
fruits = ['apple', 'banana'] fruits.insert(1, 'cherry') print(fruits) # Εμφανίζει: ['apple', 'cherry', 'banana']
fruits = ['apple', 'banana']
fruits.insert(1, 'cherry')
print(fruits)  # Εμφανίζει: ['apple', 'cherry', 'banana']
  1. remove(): Αφαιρεί το πρώτο στοιχείο με τη συγκεκριμένη τιμή από τη λίστα.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana', 'cherry']
fruits.remove('banana')
print(fruits) # Εμφανίζει: ['apple', 'cherry']
fruits = ['apple', 'banana', 'cherry'] fruits.remove('banana') print(fruits) # Εμφανίζει: ['apple', 'cherry']
fruits = ['apple', 'banana', 'cherry']
fruits.remove('banana')
print(fruits)  # Εμφανίζει: ['apple', 'cherry']

[adinserter block=”2″]

  1. pop(): Αφαιρεί το στοιχείο στην καθορισμένη θέση της λίστας και το επιστρέφει.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana', 'cherry']
removed_item = fruits.pop(1)
print(removed_item) # Εμφανίζει: 'banana'
print(fruits) # Εμφανίζει: ['apple', 'cherry']
fruits = ['apple', 'banana', 'cherry'] removed_item = fruits.pop(1) print(removed_item) # Εμφανίζει: 'banana' print(fruits) # Εμφανίζει: ['apple', 'cherry']
fruits = ['apple', 'banana', 'cherry']
removed_item = fruits.pop(1)
print(removed_item)  # Εμφανίζει: 'banana'
print(fruits)  # Εμφανίζει: ['apple', 'cherry']
  1. sort(): Ταξινομεί τα στοιχεία της λίστας.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['banana', 'apple', 'cherry']
fruits.sort()
print(fruits) # Εμφανίζει: ['apple', 'banana', 'cherry']
fruits = ['banana', 'apple', 'cherry'] fruits.sort() print(fruits) # Εμφανίζει: ['apple', 'banana', 'cherry']
fruits = ['banana', 'apple', 'cherry']
fruits.sort()
print(fruits) # Εμφανίζει: ['apple', 'banana', 'cherry']
  1. reverse(): Αντιστρέφει τη σειρά των στοιχείων της λίστας.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana', 'cherry']
fruits.reverse()
print(fruits) # Εμφανίζει: ['cherry', 'banana', 'apple']
fruits = ['apple', 'banana', 'cherry'] fruits.reverse() print(fruits) # Εμφανίζει: ['cherry', 'banana', 'apple']
fruits = ['apple', 'banana', 'cherry']
fruits.reverse()
print(fruits)  # Εμφανίζει: ['cherry', 'banana', 'apple']
  1. count(): Μετρά τον αριθμό των στοιχείων με τη συγκεκριμένη τιμή.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana', 'cherry', 'apple']
count_apples = fruits.count('apple')
print(count_apples) # Εμφανίζει: 2
fruits = ['apple', 'banana', 'cherry', 'apple'] count_apples = fruits.count('apple') print(count_apples) # Εμφανίζει: 2
fruits = ['apple', 'banana', 'cherry', 'apple']
count_apples = fruits.count('apple')
print(count_apples)  # Εμφανίζει: 2
  1. index(): Επιστρέφει τη θέση του πρώτου στοιχείου με τη συγκεκριμένη τιμή.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana', 'cherry']
index_cherry = fruits.index('cherry')
print(index_cherry) # Εμφανίζει: 2
fruits = ['apple', 'banana', 'cherry'] index_cherry = fruits.index('cherry') print(index_cherry) # Εμφανίζει: 2
fruits = ['apple', 'banana', 'cherry']
index_cherry = fruits.index('cherry')
print(index_cherry)  # Εμφανίζει: 2
  1. clear(): Αφαιρεί όλα τα στοιχεία από τη λίστα.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fruits = ['apple', 'banana', 'cherry']
fruits.clear()
print(fruits) # Εμφανίζει: []
fruits = ['apple', 'banana', 'cherry'] fruits.clear() print(fruits) # Εμφανίζει: []
fruits = ['apple', 'banana', 'cherry']
fruits.clear()
print(fruits)  # Εμφανίζει: []

Αυτές είναι μερικές από τις βασικές μεθόδους για λίστες που παρέχονται από την Python. Μπορείτε να τις χρησιμοποιήσετε για να επεξεργαστείτε και να διαχειριστείτε τα δεδομένα σας με πιο αποτελεσματικό τρόπο.

Δωρεα μεσω Paypal

Για την κάλυψη αναγκών φιλοξενίας και δημιουργίας περιεχομένου.

κατηγοριες μαθηματων

Ιστορικο ενοτητων

top
error: Content is protected !!
Μετάβαση σε γραμμή εργαλείων