Daftar adalah salah satu dari 4 tipe data bawaan di Python yang digunakan untuk menyimpan kumpulan data, 3 lainnya adalah Tuple, Set, dan Kamus, semuanya dengan kualitas dan penggunaan yang berbeda Show
Daftar dibuat menggunakan tanda kurung siku ContohBuat Daftar daftar ini = ["apel", "pisang", "ceri"] Daftar itemItem daftar diurutkan, dapat diubah, dan memungkinkan nilai duplikat Item daftar diindeks, item pertama memiliki indeks DipesanKetika kami mengatakan bahwa daftar diurutkan, itu berarti item memiliki urutan yang ditentukan, dan urutan itu tidak akan berubah Jika Anda menambahkan item baru ke daftar, item baru tersebut akan ditempatkan di akhir daftar Catatan. Ada beberapa metode daftar yang akan mengubah urutan, tetapi secara umum. urutan item tidak akan berubah Dapat diubahDaftar dapat diubah, artinya kita dapat mengubah, menambah, dan menghapus item dalam daftar setelah dibuat Izinkan DuplikatKarena daftar diindeks, daftar dapat memiliki item dengan nilai yang sama ContohDaftar memungkinkan nilai duplikat thislist = ["apel", "pisang", "ceri", "apel", "ceri"] Panjang DaftarUntuk menentukan berapa banyak item yang dimiliki daftar, gunakan fungsi ContohCetak jumlah item dalam daftar daftar ini = ["apel", "pisang", "ceri"] Item Daftar - Tipe DataItem daftar dapat berupa tipe data apa pun ContohTipe data string, int dan boolean list1 = ["apel", "pisang", "ceri"] Daftar dapat berisi tipe data yang berbeda ContohDaftar dengan string, bilangan bulat, dan nilai boolean list1 = ["abc", 34, Benar, 40, "laki-laki"] Cobalah sendiri "jenis()Dari perspektif Python, daftar didefinisikan sebagai objek dengan tipe data 'daftar' ContohApa tipe data dari daftar? daftarku = ["apel", "pisang", "ceri"] Daftar() KonstruktorDimungkinkan juga untuk menggunakan konstruktor list() saat membuat daftar baru ContohMenggunakan konstruktor thislist = list(("apple", "banana", "cherry")) # perhatikan tanda kurung bulat ganda Koleksi Python (Array)Ada empat tipe data koleksi dalam bahasa pemrograman Python
*Set item tidak dapat diubah, tetapi Anda dapat menghapus dan/atau menambahkan item kapan pun Anda mau **Pada Python versi 3. 7, kamus dipesan. Dalam Python 3. 6 dan sebelumnya, kamus tidak diurutkan Saat memilih tipe koleksi, akan sangat berguna untuk memahami properti dari tipe tersebut. Memilih jenis yang tepat untuk kumpulan data tertentu dapat berarti retensi makna, dan dapat berarti peningkatan efisiensi atau keamanan Kuasai dasar-dasar analisis data dengan Python hanya dalam empat jam. Kursus online ini akan memperkenalkan antarmuka Python dan menjelajahi paket-paket populerLihat Detail Panah Kanan Mulai kursusPiton tingkat menengahPemula4 jam 909. 6K Level up your data science skills by creating visualizations using Matplotlib and manipulating DataFrames with pandas.Lihat Detail Panah Kanan Mulai kursusPengantar Ilmu Data dengan PythonPemula4 jam 423. 1K Selami ilmu data menggunakan Python dan pelajari cara menganalisis dan memvisualisasikan data Anda secara efektif. Tidak diperlukan pengalaman atau keterampilan pengkodeanDaftar 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.
Contoh daftar dengan PythonDi sini kami membuat Daftar Python menggunakan [] Python3List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5] List with the use of Mixed Values: [1, 2, 'Geeks', 4, 'For', 6, 'Geeks']0 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']2 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']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']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']5 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']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']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']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 Accessing 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 PythonDaftar dengan Python dapat dibuat hanya dengan menempatkan urutan di dalam tanda kurung siku[]. Tidak seperti Sets, daftar tidak memerlukan fungsi bawaan untuk membuat daftar.
Contoh 1. Membuat daftar dengan PythonPython3Accessing 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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks9 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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']2 Accessing a element from a Multi-Dimensional list For Geeks9 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']4 Accessing element using negative indexing Geeks For1 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']4 Accessing element using negative indexing Geeks For3 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']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 Accessing a element from the list Geeks Geeks8 Accessing element using negative indexing Geeks For7 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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']2 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']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']4 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']0 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']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']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']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 Accessing a element from the list Geeks Geeks8 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']6 Accessing 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 Accessing a element from the list Geeks Geeks8 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']2 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2 Enter 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']9 Accessing a element from the list Geeks Geeks8 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']2 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3 Keluaran Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks Kompleksitas untuk Membuat DaftarKompleksitas Waktu. O(1) Kompleksitas Ruang. Pada) Contoh 2. Membuat daftar dengan beberapa elemen berbeda atau duplikatDaftar mungkin berisi nilai duplikat dengan posisi berbeda dan karenanya, banyak nilai berbeda atau duplikat dapat diteruskan sebagai urutan pada saat pembuatan daftar Python3Initial 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']2 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']]6 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']4 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12 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']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 Accessing a element from the list Geeks Geeks8 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks16 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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']2 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']]6 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']4 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']_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']9 Accessing a element from the list Geeks Geeks8 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks44 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing a element from a Multi-Dimensional list For Geeks0 Keluaran 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'] Mengakses elemen dari DaftarUntuk 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 Python3Accessing 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']2 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']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']4 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']0 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']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']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']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']9 Accessing a element from the list Geeks Geeks8 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks67 Accessing 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 Accessing a element from the list Geeks Geeks8 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']2 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2 Enter 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']9 Accessing a element from the list Geeks Geeks8 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']2 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]8 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3 Keluaran Accessing 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 Geeks85 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks36 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks89 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32 Blank 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']9 Accessing a element from the list Geeks Geeks8 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks97 Accessing 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 Accessing a element from the list Geeks Geeks8 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']2 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2 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']04 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']]6 Enter 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']9 Accessing a element from the list Geeks Geeks8 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']2 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']]6 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']04 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3 Keluaran Accessing a element from a Multi-Dimensional list For Geeks Pengindeksan negatifDalam 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. Python3Accessing 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']2 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']]6 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']4 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']_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']9 Accessing a element from the list Geeks Geeks8 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']36 Accessing 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']9 Accessing a element from the list Geeks Geeks8 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']2 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']43 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']]6 Enter 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']9 Accessing a element from the list Geeks Geeks8 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']2 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']43 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]3 Keluaran Accessing element using negative indexing Geeks For Kompleksitas untuk Mengakses elemen dalam DaftarKompleksitas Waktu. O(1) Kompleksitas Ruang. O(1) Mendapatkan ukuran daftar PythonPython len() digunakan untuk mendapatkan panjang daftar Python3Accessing 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']55 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']9 Accessing a element from the list Geeks Geeks8 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']60 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']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']63 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']2________21______9 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']4 Accessing element using negative indexing Geeks For1 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']4 Accessing element using negative indexing Geeks For3 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']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 Accessing a element from the list Geeks Geeks8 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']60 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']75 Keluaran 0 3 Mengambil Input dari Daftar PythonKita dapat mengambil input dari daftar elemen sebagai string, integer, float, dll. Tapi yang default adalah string Contoh 1. Python3List with the use of 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']81 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']83 Accessing a element from the list Geeks Geeks8 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']85 Accessing 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']88 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']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']9 Accessing a element from the list Geeks Geeks8 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']93 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']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']95 Keluaran Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS'] Contoh 2 PitonList with the use of 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']97 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']99 Accessing a element from the list Geeks Geeks8 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']83 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks03 Accessing 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']88 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 Geeks09 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks11 Accessing a element from the list Geeks Geeks8 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']99 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']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']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']9 Accessing a element from the list Geeks Geeks8 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']93 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']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 PythonMetode 1. Menggunakan append() metodeElemen 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() Python3Accessing 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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks31 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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 Geeks4 Accessing a element from the list Geeks Geeks40 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']]6 Accessing a element from a Multi-Dimensional list For Geeks0 Accessing a element from the list Geeks Geeks4 Accessing a element from the list Geeks Geeks40________63______8 Accessing a element from a Multi-Dimensional list For Geeks0 Accessing a element from the list Geeks Geeks4 Accessing a element from the list Geeks Geeks40 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks53 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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 Geeks62 Accessing a element from the list Geeks Geeks63 Accessing a element from the list Geeks Geeks64 Accessing a element from the list Geeks Geeks8 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']]6 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00 Accessing a element from the list Geeks Geeks69 Accessing a element from the list Geeks Geeks70 Accessing a element from the list Geeks Geeks4 Accessing 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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks75 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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 Geeks4 Accessing a element from the list Geeks Geeks83 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10 Accessing 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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks90 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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']63 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']2 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks36 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32 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']8 ________10 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']_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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from a Multi-Dimensional list For Geeks08 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing a element from a Multi-Dimensional list For Geeks0 Keluaran 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']] Kompleksitas untuk Menambahkan elemen dalam metode Lists(append())Kompleksitas Waktu. O(1) Kompleksitas Ruang. O(1) Metode 2. Menggunakan insert() metodemetode 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). Python3Accessing 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']2 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']]6 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']4 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: 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']4 Blank 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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from a Multi-Dimensional list For Geeks31 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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 Geeks4 Accessing a element from a Multi-Dimensional list For Geeks41 Blank List: [] List of numbers: [10, 20, 14] List Items: 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']4 Accessing a element from a Multi-Dimensional list For Geeks44 Accessing a element from a Multi-Dimensional list For Geeks0 Accessing a element from the list Geeks Geeks4 Accessing a element from a Multi-Dimensional list For Geeks41 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]2 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from a Multi-Dimensional list For Geeks54 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing a element from a Multi-Dimensional list For Geeks0 Keluaran Blank 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.
Python3Accessing 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']2 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']]6 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']4 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: 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']4 Blank 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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from a Multi-Dimensional list For Geeks31 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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 Geeks4 Accessing a element from a Multi-Dimensional list For Geeks86 Accessing a element from a Multi-Dimensional list For Geeks87 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks32 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']4 Accessing a element from a Multi-Dimensional list For Geeks91 Enter 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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from a Multi-Dimensional list For Geeks95 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing a element from a Multi-Dimensional list For Geeks0 Keluaran Blank 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 DaftarDaftar dapat dibalik dengan menggunakan metode reverse() di Python Python3Accessing element using negative indexing Geeks For_01 Accessing element using negative indexing Geeks For02 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']2 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']]6 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']4 Enter 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 Keluaran Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_2 Menghapus Elemen dari DaftarMetode 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
Contoh 1 Python3Accessing 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']2 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']]6 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']4 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']_71__________04____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________G Accessing element using negative indexing Geeks For40 Accessing element using negative indexing Geeks For41________0______4 Accessing a element from a Multi-Dimensional list For Geeks87 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']4 Accessing element using negative indexing Geeks For45 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']4 Accessing a element from a Multi-Dimensional list For Geeks9 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']4 Accessing 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']9 Accessing a element from the list Geeks Geeks8 Accessing a element from a Multi-Dimensional list For Geeks31 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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 Geeks4 Accessing element using negative indexing Geeks For64 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12 Accessing a element from a Multi-Dimensional list For Geeks0 Accessing a element from the list Geeks Geeks4 Accessing element using negative indexing Geeks For64 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing element using negative indexing Geeks For73 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing a element from a Multi-Dimensional list For Geeks0 Keluaran Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_3 Contoh 2 Python3Accessing 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']2 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']]6 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']4 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']_71__________04____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________G Accessing element using negative indexing Geeks For40 Accessing element using negative indexing Geeks For41________0______4 Accessing a element from a Multi-Dimensional list For Geeks87 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']4 Accessing element using negative indexing Geeks For45 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']4 Accessing a element from a Multi-Dimensional list For Geeks9 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']4 Accessing 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 Geeks62 Accessing a element from the list Geeks Geeks63 Accessing a element from the list Geeks Geeks64 Accessing a element from the list Geeks Geeks8 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']]6 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12 Accessing a element from the list Geeks Geeks69 Accessing a element from the list Geeks Geeks70 Accessing a element from the list Geeks Geeks4 0 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']9 Accessing a element from the list Geeks Geeks8 0 324 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing a element from a Multi-Dimensional list For Geeks0 Keluaran Blank 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 Python3Accessing 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']2 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']]6 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']4 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: 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']4 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks00_______0______4_______8__1_____
0 3_43 0 3_44 ________10 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']_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']9 Accessing a element from the list Geeks Geeks8 0 349 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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 Geeks4 0 359________63______8 Accessing 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 Accessing a element from the list Geeks Geeks8 0 364 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing a element from a Multi-Dimensional list For Geeks0 Keluaran Blank 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 DaftarKita 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
Untuk mencetak elemen dari penggunaan akhir
Untuk mencetak elemen dari Indeks tertentu hingga penggunaan akhir
Untuk mencetak seluruh daftar dalam urutan terbalik, gunakan
Catatan – Untuk mencetak elemen Daftar dari belakang, gunakan Indeks Negatif. MEMAHAMI SLICING OF LIST
Python3Accessing 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']2 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']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']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']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']_4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444 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 Accessing a element from the list Geeks Geeks8 Accessing a element from a Multi-Dimensional list For Geeks31 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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']13 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 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']2 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks04 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']18 Accessing a element from a Multi-Dimensional list For Geeks87 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']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 Accessing a element from the list Geeks Geeks8 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']23 Accessing 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']13 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 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']2 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks12 Enter 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']_9 Accessing a element from the list Geeks Geeks8 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']37 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']38 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']39 Accessing 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']13 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 Geeks4 Enter 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']9 Accessing a element from the list Geeks Geeks8 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']51 Accessing 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 Keluaran Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_6 Pemotongan daftar indeks negatifPython3Accessing 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']2 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']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']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']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']_4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444 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 Accessing a element from the list Geeks Geeks8 Accessing a element from a Multi-Dimensional list For Geeks31 Accessing 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 Accessing a element from the list Geeks Geeks8 Accessing a element from the list Geeks Geeks4 Accessing 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']13 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 Geeks4 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']99 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']43 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10 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']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 Accessing a element from the list Geeks Geeks8 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]05 Accessing 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']13 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 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']2 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']43 Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks10 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']18 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']43 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']]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']9 Accessing a element from the list Geeks Geeks8 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]23 Accessing 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']13 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 Geeks4 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]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']43 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']]6 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']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 Accessing a element from the list Geeks Geeks8 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]38 Accessing 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 Keluaran Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks7 Daftar PemahamanPemahaman 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
Contoh. Python3Enter 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]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']1 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]48 Enter 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]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]53 Accessing a element from the list Geeks Geeks63 Accessing a element from the list Geeks Geeks64 Accessing a element from the list Geeks Geeks8 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']]6 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']4 Accessing element using negative indexing Geeks For49 Accessing a element from a Multi-Dimensional list For Geeks0 Enter 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]53 Enter 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']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']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']]6 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']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 Keluaran Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_8 Untuk pemahaman yang lebih baik, kode di atas mirip dengan sebagai berikut. Python3Enter 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]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']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]53 Accessing a element from the list Geeks Geeks63 Accessing a element from the list Geeks Geeks64 Accessing a element from the list Geeks Geeks8 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']]6 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']4 Accessing element using negative indexing Geeks For49 Accessing a element from the list Geeks Geeks69 Accessing a element from the list Geeks Geeks70 Enter 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]53 Enter 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']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']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']]6 Enter elements: GEEKS FOR GEEKS The list is: ['GEEKS', 'FOR', 'GEEKS']18 ________32______40 Enter the size of list : 4 Enter the integer elements: 6 3 9 10 The list is: [6, 3, 9, 10]94 Enter 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]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 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 Keluaran Blank List: [] List of numbers: [10, 20, 14] List Items: Geeks Geeks_8 Lihat artikel di bawah ini untuk mendapatkan informasi mendetail tentang Pemahaman Daftar
Contoh Dasar pada Daftar Python
Untuk Berlatih operasi daftar dasar, silakan baca artikel ini – Daftar program Python Daftar MetodeFunctionDescriptionAppend()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 DaftarFunctionDescriptionreduce()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.
{ “@konteks”. “https. //skema. org/”, “@type”. “Artikel”, “EntityOfPage utama”. { "@jenis". “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". { "@jenis". "Nama Organisasi". “GeeksforGeeks” }, “penerbit”. { "@jenis". "Nama Organisasi". "GeeksforGeeks", "logo". { "@jenis". "Objek Gambar", "url". “https. //media. geeksforgeeks. org/wp-content/cdn-uploads/gfg_200x200-min. png” } }, “tanggalDiterbitkan”. “18-07-2022”, “tanggalDimodifikasi”. “21-07-2022” } Bagaimana cara menyimpan daftar sebagai file dengan Python?Solusi paling sederhana bagi Python untuk menulis daftar ke file adalah menggunakan file. write() metode yang menulis semua item dari daftar ke file . Metode open() membuka file dalam mode w. Daftar ini diulangi dan semua item ditulis satu per satu.
Bagaimana daftar disimpan?Daftar, kemudian, disimpan dalam potongan memori berbeda yang dihubungkan bersama dengan pointer , yang memungkinkan penggunaan memori yang efisien secara umum dan tidak . Ini juga memungkinkan manipulasi pointer yang mudah dan cepat saat mengubah daftar.
Bagaimana cara menyimpan daftar di database menggunakan Python?# Menggunakan daftar Python sebagai database . Membuat file basis data Tambahkan entri ke penyimpanan data Lihat entri di penyimpanan data Menggunakan database di app. py Memisahkan data dari tampilan Bisakah Anda menyimpan daftar dalam satu set Python?Daftar adalah objek yang dapat diubah dan karenanya tidak dapat di-hash dengan Python. Padahal, set di Python tidak dapat diubah dan tidak mengizinkan objek yang tidak dapat di-hash. Oleh karena itu, Python tidak mengizinkan set untuk menyimpan daftar . Anda tidak dapat menambahkan daftar ke kumpulan. |