Daftar Python seperti array berukuran dinamis, dideklarasikan dalam bahasa lain (vektor dalam C++ dan ArrayList di Jawa). Dalam bahasa sederhana, daftar adalah kumpulan hal-hal, diapit [ ] dan dipisahkan dengan koma.
Daftar adalah tipe data urutan yang digunakan untuk menyimpan kumpulan data. Tuples dan String adalah tipe lain dari tipe data sequence
Contoh daftar dengan Python
Di sini kami membuat Daftar Python menggunakan []
Python3
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']0List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']5List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks0
Keluaran
["Geeks", "for", "Geeks"]Daftar adalah wadah paling sederhana yang merupakan bagian integral dari bahasa Python. Daftar tidak harus selalu homogen yang menjadikannya alat yang paling kuat di Python. Daftar tunggal mungkin berisi Tipe Data seperti Integer, String, serta Objek. Daftar dapat berubah, dan karenanya, dapat diubah bahkan setelah dibuat
Membuat Daftar dengan Python
Daftar dengan Python dapat dibuat hanya dengan menempatkan urutan di dalam tanda kurung siku[]. Tidak seperti Sets, daftar tidak memerlukan fungsi bawaan untuk membuat daftar.
Catatan. Tidak seperti Set, daftar mungkin berisi elemen yang dapat diubah.
Contoh 1. Membuat daftar dengan Python
Python3
Accessing a element from the list Geeks Geeks_1
Accessing a element from the list Geeks Geeks_2
Accessing a element from the list Geeks Geeks_3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks6
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks9Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from a Multi-Dimensional list For Geeks5
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Accessing a element from a Multi-Dimensional list For Geeks9List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For1List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing element using negative indexing Geeks For7Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
0 3_3
0 3_4
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']0List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']6Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks
Kompleksitas untuk Membuat Daftar
Kompleksitas Waktu. O(1)
Kompleksitas Ruang. Pada)
Contoh 2. Membuat daftar dengan beberapa elemen berbeda atau duplikat
Daftar mungkin berisi nilai duplikat dengan posisi berbeda dan karenanya, banyak nilai berbeda atau duplikat dapat diteruskan sebagai urutan pada saat pembuatan daftar
Python3
Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]_0
Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]_1
Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]_2
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks16Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]_0
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks23
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks24
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8_______List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_71__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________g
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks44Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
KeluaranList with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
Mengakses elemen dari Daftar
Untuk mengakses item daftar merujuk ke nomor indeks. Gunakan operator indeks [ ] untuk mengakses item dalam daftar. Indeks harus berupa bilangan bulat. Daftar bersarang diakses menggunakan pengindeksan bersarang.
Contoh 1. Mengakses elemen dari daftar
Python3
Accessing a element from the list Geeks Geeks_1
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks51
Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]_0
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks53
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']0List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks63
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks64
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks67Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
KeluaranAccessing a element from the list Geeks Geeks
Contoh 2. Mengakses elemen dari daftar multidimensi
Python3
________71______81
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks82
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks85Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks36Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks89Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks91
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_92
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_93
Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_94
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks97Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']04Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']04Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
KeluaranAccessing a element from a Multi-Dimensional list For Geeks
Pengindeksan negatif
Dalam Python, indeks urutan negatif mewakili posisi dari akhir array. Daripada harus menghitung offset seperti pada List[len(List)-3], cukup tulis saja List[-3]. Pengindeksan negatif berarti mulai dari akhir, -1 mengacu pada item terakhir, -2 mengacu pada item kedua terakhir, dll.
Python3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8_______List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_71__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________g
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_32
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_33
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']36Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_38
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']43Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_46
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']43Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
KeluaranAccessing element using negative indexing Geeks For
Kompleksitas untuk Mengakses elemen dalam Daftar
Kompleksitas Waktu. O(1)
Kompleksitas Ruang. O(1)
Mendapatkan ukuran daftar Python
Python len() digunakan untuk mendapatkan panjang daftar
Python3
Accessing a element from the list Geeks Geeks_3
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']55List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks6
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']60List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']61
Accessing a element from a Multi-Dimensional list For Geeks5
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']63List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2________21______9List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For1List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']60List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']75
Keluaran0 3
Mengambil Input dari Daftar Python
Kita dapat mengambil input dari daftar elemen sebagai string, integer, float, dll. Tapi yang default adalah string
Contoh 1.
Python3
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_76
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_77
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_78
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_79
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_80
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']81List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']83Accessing a element from the list Geeks Geeks8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']85Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_87
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']88List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']90
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']93List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']94List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']95
Keluaran
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']Contoh 2
Piton
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_96
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']97List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']99Accessing a element from the list Geeks Geeks8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']83Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks03Accessing a element from the list Geeks Geeks04
Accessing a element from the list Geeks Geeks_05
Accessing a element from the list Geeks Geeks_06
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']88List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks09Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks11Accessing a element from the list Geeks Geeks8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']99List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']83________10______16
Accessing a element from the list Geeks Geeks_17
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_95
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']93List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']94
Keluaran
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]Untuk mengetahui lebih lanjut lihat ini
Menambahkan Elemen ke Daftar Python
Metode 1. Menggunakan append() metode
Elemen dapat ditambahkan ke Daftar dengan menggunakan fungsi append() bawaan. Hanya satu elemen pada satu waktu yang dapat ditambahkan ke daftar dengan menggunakan metode append(), untuk penambahan beberapa elemen dengan metode append(), loop digunakan. Tupel juga dapat ditambahkan ke daftar dengan menggunakan metode append karena tupel tidak dapat diubah. Tidak seperti Set, Daftar juga dapat ditambahkan ke daftar yang sudah ada dengan menggunakan metode append()
Python3
Accessing a element from the list Geeks Geeks_1
Accessing a element from the list Geeks Geeks_24
Accessing a element from the list Geeks Geeks_3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks6
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks31Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from the list Geeks Geeks_37
Accessing a element from the list Geeks Geeks_38
Accessing a element from the list Geeks Geeks4Accessing a element from the list Geeks Geeks40Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from the list Geeks Geeks4Accessing a element from the list Geeks Geeks40________63______8Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from the list Geeks Geeks4Accessing a element from the list Geeks Geeks40Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks53Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from the list Geeks Geeks_59
Accessing a element from the list Geeks Geeks_60
Accessing a element from the list Geeks Geeks_61 Accessing a element from the list Geeks Geeks62Accessing a element from the list Geeks Geeks63 Accessing a element from the list Geeks Geeks64Accessing a element from the list Geeks Geeks8Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00Accessing a element from the list Geeks Geeks69
Accessing a element from the list Geeks Geeks70Accessing a element from the list Geeks Geeks4Accessing a element from the list Geeks Geeks72
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks75Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from the list Geeks Geeks_81
Accessing a element from the list Geeks Geeks4Accessing a element from the list Geeks Geeks83Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10Accessing a element from the list Geeks Geeks04
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks90Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from the list Geeks Geeks_96
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']63List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks36List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
________10List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_21_______05
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from a Multi-Dimensional list For Geeks08Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
KeluaranInitial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]
Kompleksitas untuk Menambahkan elemen dalam metode Lists(append())
Kompleksitas Waktu. O(1)
Kompleksitas Ruang. O(1)
Metode 2. Menggunakan insert() metode
metode append() hanya berfungsi untuk penambahan elemen di akhir List, untuk penambahan elemen pada posisi yang diinginkan, digunakan metode insert(). Tidak seperti append() yang hanya membutuhkan satu argumen, metode insert() membutuhkan dua argumen (posisi, nilai).
Python3
Accessing a element from the list Geeks Geeks_1
Accessing a element from the list Geeks Geeks_24
Accessing a element from a Multi-Dimensional list For Geeks16
Accessing a element from the list Geeks Geeks_3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00________0______8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from a Multi-Dimensional list For Geeks31Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from a Multi-Dimensional list For Geeks37
Accessing a element from a Multi-Dimensional list For Geeks_38
Accessing a element from a Multi-Dimensional list For Geeks39
Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks41Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing a element from a Multi-Dimensional list For Geeks44Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks41Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from a Multi-Dimensional list For Geeks54Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_0
Kompleksitas untuk Menambahkan elemen dalam metode Lists(insert())
Kompleksitas Waktu. Pada)
Kompleksitas Ruang. O(1)
Metode 3. Menggunakan metode extend()
Selain metode append() dan insert(), ada satu metode lagi untuk Penambahan elemen, yaitu extend(), metode ini digunakan untuk menambahkan beberapa elemen sekaligus di akhir daftar.
Catatan. metode append() dan extend() hanya dapat menambahkan elemen di bagian akhir
Python3
Accessing a element from the list Geeks Geeks_1
Accessing a element from the list Geeks Geeks_24
Accessing a element from the list Geeks Geeks_3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00________0______8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from a Multi-Dimensional list For Geeks31Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from a Multi-Dimensional list For Geeks82
Accessing a element from a Multi-Dimensional list For Geeks83
Accessing a element from a Multi-Dimensional list For Geeks84
Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks86Accessing a element from a Multi-Dimensional list For Geeks87List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing a element from a Multi-Dimensional list For Geeks91Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from a Multi-Dimensional list For Geeks95Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_1
Kompleksitas untuk Menambahkan elemen dalam metode Lists(extend())
Kompleksitas Waktu. Pada)
Kompleksitas Ruang. O(1)
Membalik Daftar
Daftar dapat dibalik dengan menggunakan metode reverse() di Python
Python3
Accessing element using negative indexing Geeks For_01
Accessing element using negative indexing Geeks For02List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8________________________________________________________________________________________________________________________________________________________________________________________________________________________________________G
Accessing element using negative indexing Geeks For_19
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________32______21
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_2
Menghapus Elemen dari Daftar
Metode 1. Menggunakan metode hapus()
Elemen dapat dihapus dari Daftar dengan menggunakan fungsi remove() bawaan tetapi Kesalahan muncul jika elemen tidak ada dalam daftar. Metode Remove() hanya menghapus satu elemen pada satu waktu, untuk menghapus berbagai elemen, digunakan iterator. Metode remove() menghapus item yang ditentukan
Catatan. Hapus metode dalam Daftar hanya akan menghapus kemunculan pertama dari elemen yang dicari
Contoh 1
Python3
Accessing a element from the list Geeks Geeks_1
Accessing element using negative indexing Geeks For_23
Accessing a element from the list Geeks Geeks_3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8___________List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_71___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________4
Accessing element using negative indexing Geeks For40Accessing element using negative indexing Geeks For41________0______4Accessing a element from a Multi-Dimensional list For Geeks87List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For45List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing a element from a Multi-Dimensional list For Geeks9List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For49________0______14________4______4
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from a Multi-Dimensional list For Geeks31Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Accessing element using negative indexing Geeks For_61
Accessing element using negative indexing Geeks For_62
Accessing a element from the list Geeks Geeks4Accessing element using negative indexing Geeks For64Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12Accessing a element from a Multi-Dimensional list For Geeks0
Accessing a element from the list Geeks Geeks4Accessing element using negative indexing Geeks For64Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing element using negative indexing Geeks For73Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_3
Contoh 2
Python3
Accessing a element from the list Geeks Geeks_3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8___________List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_71___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________4
Accessing element using negative indexing Geeks For40Accessing element using negative indexing Geeks For41________0______4Accessing a element from a Multi-Dimensional list For Geeks87List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For45List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing a element from a Multi-Dimensional list For Geeks9List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For49________0______14________4______4
Accessing element using negative indexing Geeks For_61
0 3_09
Accessing a element from the list Geeks Geeks_61 Accessing a element from the list Geeks Geeks62Accessing a element from the list Geeks Geeks63 Accessing a element from the list Geeks Geeks64Accessing a element from the list Geeks Geeks8Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12Accessing a element from the list Geeks Geeks69
Accessing a element from the list Geeks Geeks70Accessing a element from the list Geeks Geeks40 321
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks80 324Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_4
Kompleksitas untuk Menghapus elemen dalam metode Lists(remove())
Kompleksitas Waktu. Pada)
Kompleksitas Ruang. O(1)
Metode 2. Menggunakan metode pop()
fungsi pop () juga dapat digunakan untuk menghapus dan mengembalikan elemen dari daftar, tetapi secara default hanya menghapus elemen terakhir dari daftar, untuk menghapus elemen dari posisi tertentu dari Daftar, indeks elemen diteruskan
Python3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00_______0______4_______8__1_____
0 3_43
0 3_44
________10List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_44_______46
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks80 349Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
0 3_55
0 3_56
0 3_44
Accessing a element from the list Geeks Geeks40 359________63______8Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks80 364Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks5
Kompleksitas untuk Menghapus elemen dalam metode Lists(pop())
Kompleksitas Waktu. O(1)/O(n) (O(1) untuk menghapus elemen terakhir, O(n) untuk menghapus elemen pertama dan tengah)
Kompleksitas Ruang. O(1)
Mengiris Daftar
Kita bisa mendapatkan substring dan sublist menggunakan sebuah slice. Dalam Daftar Python, ada beberapa cara untuk mencetak seluruh daftar dengan semua elemen, tetapi untuk mencetak rentang elemen tertentu dari daftar, kami menggunakan operasi Slice.
Operasi irisan dilakukan pada Daftar dengan menggunakan tanda titik dua (. ).
Untuk mencetak elemen dari awal hingga penggunaan rentang
[. Indeks]
Untuk mencetak elemen dari penggunaan akhir
[. -Indeks]
Untuk mencetak elemen dari Indeks tertentu hingga penggunaan akhir
[Indeks. ]
Untuk mencetak seluruh daftar dalam urutan terbalik, gunakan
[. -1]
Catatan – Untuk mencetak elemen Daftar dari belakang, gunakan Indeks Negatif.
MEMAHAMI SLICING OF LIST
- pr[0] mengakses item pertama, 2
- pr[-4] mengakses item keempat dari akhir, 5
- pr[2. ] mengakses [5, 7, 11, 13], daftar item dari ketiga hingga terakhir
- pr[. 4] mengakses [2, 3, 5, 7], daftar item dari pertama hingga keempat
- pr[2. 4] mengakses [5, 7], daftar item dari ketiga hingga kelima
- pr[1. 2] mengakses [3, 7, 13], item alternatif, mulai dari item kedua
Python3
Accessing a element from the list Geeks Geeks_1
Accessing element using negative indexing Geeks For_23
Accessing a element from the list Geeks Geeks_3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']76List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']78List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4________444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
Accessing element using negative indexing Geeks For40________4440___89___________List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from a Multi-Dimensional list For Geeks31Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']11
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']12
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']13List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']18Accessing a element from a Multi-Dimensional list For Geeks87List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']23Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________51______26
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']27
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']28
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']13List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']34
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_9Accessing a element from the list Geeks Geeks8Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']37
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']38Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']39Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________51______26
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']43
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']44
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']13List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks4Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']48
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']51Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________51______26
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_6
Pemotongan daftar indeks negatif
Python3
Accessing a element from the list Geeks Geeks_3
Accessing a element from the list Geeks Geeks4 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']76List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']78List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4________444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
Accessing element using negative indexing Geeks For40________4440___89___________List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']_4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from a Multi-Dimensional list For Geeks31Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Accessing a element from the list Geeks Geeks4Accessing a element from a Multi-Dimensional list For Geeks0
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']_94
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']_95
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']13List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks4Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']99List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']43Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]05Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________51______26
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']11
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]10
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']13List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks4List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']2List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']43Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']18List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']43Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6________0______8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]23Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________51______26
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]27
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']12
Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']13List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks4Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]32List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']43Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9Accessing a element from the list Geeks Geeks8Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]38Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________51______26
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks7
Daftar Pemahaman
Pemahaman Daftar Python digunakan untuk membuat daftar baru dari iterable lain seperti tupel, string, array, daftar, dll. Pemahaman daftar terdiri dari tanda kurung yang berisi ekspresi, yang dijalankan untuk setiap elemen bersama dengan perulangan for untuk mengulangi setiap elemen.
Sintaksis
DaftarBaru = [ekspresi(elemen) untuk elemen dalam Daftarlama jika kondisi]
Contoh.
Python3
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]42
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]43
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]44
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]45
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]46List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]48Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]49Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]49 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8 Accessing a element from the list Geeks Geeks61 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]53Accessing a element from the list Geeks Geeks63 Accessing a element from the list Geeks Geeks64Accessing a element from the list Geeks Geeks8Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For49Accessing a element from a Multi-Dimensional list For Geeks0Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]61 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]53Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]63 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']8
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________63______70
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_8
Untuk pemahaman yang lebih baik, kode di atas mirip dengan sebagai berikut.
Python3
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]71
Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]46List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Accessing a element from the list Geeks Geeks6
Accessing a element from the list Geeks Geeks61 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]53Accessing a element from the list Geeks Geeks63 Accessing a element from the list Geeks Geeks64Accessing a element from the list Geeks Geeks8Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']4Accessing element using negative indexing Geeks For49Accessing a element from the list Geeks Geeks69
Accessing a element from the list Geeks Geeks70Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]61 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]53Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]63 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8 List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']1 Initial blank List: [] List after Addition of Three elements: [1, 2, 4] List after Addition of elements from 1-3: [1, 2, 4, 1, 2, 3] List after Addition of a Tuple: [1, 2, 4, 1, 2, 3, (5, 6)] List after Addition of a List: [1, 2, 4, 1, 2, 3, (5, 6), ['For', 'Geeks']]6Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']18
________32______40Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]94Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]49Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]49Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8Accessing a element from a Multi-Dimensional list For Geeks0
List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']9________63______70
KeluaranBlank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_8
Lihat artikel di bawah ini untuk mendapatkan informasi mendetail tentang Pemahaman Daftar
- Pemahaman dan Pengirisan Daftar Python
- Pemahaman Daftar Bersarang dengan Python
- Daftar pemahaman dan ord() dengan Python
Contoh Dasar pada Daftar Python
- Program python untuk menukar elemen pertama dan terakhir dalam daftar
- Program python untuk menukar dua elemen dalam daftar
- Python – Tukar elemen dalam daftar String
- Piton. Cara untuk menemukan panjang daftar
- Maksimal dua angka dengan Python
- Minimal dua angka dengan Python
Untuk Berlatih operasi daftar dasar, silakan baca artikel ini – Daftar program Python
Daftar Metode
FunctionDescriptionAppend()Tambahkan elemen ke akhir listExtend()Tambahkan semua elemen daftar ke listInsert()Masukkan item pada indeks yang ditentukanHapus()Menghapus item dari listClear()Menghapus semua item dari listIndex()Untuk mengetahui lebih lanjut, lihat artikel ini – Metode Daftar Python
Operasi yang disebutkan di atas memodifikasi daftar itu sendiri
Fungsi bawaan dengan Daftar
FunctionDescriptionreduce()menerapkan fungsi tertentu yang diteruskan dalam argumennya ke semua elemen daftar menyimpan hasil antara dan hanya mengembalikan penjumlahan akhir valuesum()Menjumlahkan angka dalam listord()Mengembalikan bilangan bulat yang mewakili titik kode Unicode dari yang diberikan . jika daftar kosong, return falselen()Mengembalikan panjang daftar atau ukuran dari listenumerate()Mengembalikan objek enumerate dari listaccumulate()menerapkan fungsi tertentu yang diteruskan dalam argumennya ke semua elemen daftar mengembalikan daftar yang berisi perantaraBaca artikel terbaru tentang Daftar
Tautan yang Berguna.
- Artikel Terbaru tentang Daftar Python
- Tutorial Python
- Soal pilihan ganda
- Semua artikel dalam Kategori Python
{ “@konteks”. “https. //skema. org/”, “@type”. “Artikel”, “EntityOfPage utama”. { "@Tipe". “Halaman Web”, “@id”. “https. // www. geeksforgeeks. org/python-list/” }, “judul”. "Daftar Python", "deskripsi". “Daftar Python sama seperti array berukuran dinamis, dideklarasikan dalam bahasa lain (vektor di C++ dan ArrayList di Java). ", "gambar". “https. //media. geeksforgeeks. org/wp-content/uploads/List-Slicing. jpg", "penulis". { "@Tipe". "Nama Organisasi". “GeeksforGeeks” }, “penerbit”. { "@Tipe". "Nama Organisasi". "GeeksforGeeks", "logo". { "@Tipe". "Objek Gambar", "url". “https. //media. geeksforgeeks. org/wp-content/cdn-uploads/gfg_200x200-min. png” } }, “tanggalDiterbitkan”. “18-07-2022”, “tanggalDimodifikasi”. “21-07-2022” }