Apa struktur daftar di python?

Misalkan kita perlu mencatat usia 5 siswa. Alih-alih membuat 5 variabel terpisah, kita cukup membuat daftar

Daftar Elemen

Buat Daftar Python

Daftar dibuat dengan Python dengan menempatkan item di dalam

languages = ["Python", "Swift", "C++"]

# access item at index 0
print[languages[0]]   # Python

# access item at index 2
print[languages[2]]   # C++
5, dipisahkan dengan koma. Sebagai contoh,

# A list with 3 integers
numbers = [1, 2, 5]

print[numbers]

# Output: [1, 2, 5]
_

Di sini, kami telah membuat daftar bernama angka dengan 3 item bilangan bulat

Daftar dapat memiliki sejumlah item dan mungkin dari jenis yang berbeda [integer, float, string, dll. ]. Sebagai contoh,

# empty list
my_list = []

# list with mixed data types
my_list = [1, "Hello", 3.4]

Akses Elemen Daftar Python

Di Python, setiap item dalam daftar dikaitkan dengan angka. Angka tersebut dikenal sebagai indeks daftar

Kita dapat mengakses elemen array menggunakan nomor indeks [0, 1, 2 …]. Sebagai contoh,

languages = ["Python", "Swift", "C++"]

# access item at index 0
print[languages[0]]   # Python

# access item at index 2
print[languages[2]]   # C++

Dalam contoh di atas, kami telah menggunakan pemahaman daftar untuk membuat daftar dengan setiap item dipangkatkan 2. Perhatikan kodenya,

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']
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']
_4_______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
Geeks
0

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
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']
1
Accessing a element from the list
Geeks
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
9
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from a Multi-Dimensional list
For
Geeks
_5

Accessing a element from the list
Geeks
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']
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
Geeks
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
For
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']
4
Accessing element using negative indexing
Geeks
For
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
Geeks
8
Accessing element using negative indexing
Geeks
For
7
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

0
3
_3

0
3
_4

Accessing a element from the list
Geeks
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']
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_______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
Geeks
8
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
6
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
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']
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
Geeks
8
Accessing a element from the list
Geeks
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']
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 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
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']
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
Geeks
00
List with the use of 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
Geeks
00
List with the use of 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
Geeks
04
List with the use of 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
Geeks
04
List with the use of 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
Geeks
04
List with the use of 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
Geeks
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']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
List with the use of 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
Geeks
8
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
16
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
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']]
0

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
_23

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
_24

Accessing a element from the list
Geeks
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']
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____75____________________________________________________________________________________________________________________________________________________________________________________________

List with the use of 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
Geeks
8
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
44
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

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 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
Geeks
_51

 

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
Geeks
_53

Accessing a element from the list
Geeks
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']
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_______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
Geeks
_63

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
_64

List with the use of 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
Geeks
8
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
67
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
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']
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
Geeks
8
Accessing a element from the list
Geeks
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']
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




Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
_81

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
_82

Accessing a element from the list
Geeks
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']
1
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
85
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
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']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
36
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
89
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
32
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
91

 

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
Geeks
8
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
97
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
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']
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
Geeks
8
Accessing a element from the list
Geeks
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']
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 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
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']
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____75____________________________________________________________________________________________________________________________________________________________________________________________

 

List with the use of 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
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']
36
Accessing a element from a Multi-Dimensional list
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']
_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
Geeks
8
Accessing a element from the list
Geeks
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']
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_______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
Geeks
8
Accessing a element from the list
Geeks
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']
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
Geeks
04
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 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']
_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
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']
_9
Accessing a element from the list
Geeks
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']
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
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']
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________25______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_______4
Accessing element using negative indexing
Geeks
For
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']
4
Accessing element using negative indexing
Geeks
For
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
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']
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 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']
_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
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']
85
Accessing a element from a Multi-Dimensional list
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']
_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
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']
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

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']
_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
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']
83
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
03
Accessing a element from the list
Geeks
Geeks
04

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
Geeks
09
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
11
Accessing a element from the list
Geeks
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']
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________14______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
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']
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 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
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']
1
Accessing a element from the list
Geeks
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
31
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

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
Geeks
4
Accessing a element from the list
Geeks
Geeks
40________76______6
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from the list
Geeks
Geeks
40
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
Geeks
0

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from the list
Geeks
Geeks
40
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
00
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
53
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

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
Geeks
62
Accessing a element from the list
Geeks
Geeks
63
Accessing a element from the list
Geeks
Geeks
64
Accessing a element from the list
Geeks
Geeks
8
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
Geeks
00
Accessing a element from the list
Geeks
Geeks
69

Accessing a element from the list
Geeks
Geeks
70
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from the list
Geeks
Geeks
72

List with the use of 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
Geeks
8
Accessing a element from the list
Geeks
Geeks
75
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from the list
Geeks
Geeks
_81

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from the list
Geeks
Geeks
83
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
List with the use of 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
Geeks
10
Accessing a element from the list
Geeks
Geeks
04

List with the use of 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
Geeks
8
Accessing a element from the list
Geeks
Geeks
90
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

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
Geeks
36
List with the use of 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
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']
8

________14

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
_25_______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
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
08
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

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[] 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
Geeks
_16

Accessing a element from the list
Geeks
Geeks
_3

Accessing a element from the list
Geeks
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']
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
Geeks
04
List with the use of 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
Geeks
00________4______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
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from a Multi-Dimensional list
For
Geeks
_37

Accessing a element from a Multi-Dimensional list
For
Geeks
_38

Accessing a element from a Multi-Dimensional list
For
Geeks
_39

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
41
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04
List with the use of 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
Geeks
44
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
41
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
Geeks
32
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
54
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

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.

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
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']
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
Geeks
04
List with the use of 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
Geeks
00________4______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
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing a element from a Multi-Dimensional list
For
Geeks
_82

Accessing a element from a Multi-Dimensional list
For
Geeks
_83

Accessing a element from a Multi-Dimensional list
For
Geeks
_84

Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
86
Accessing a element from a Multi-Dimensional list
For
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']
4
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
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']
4
Accessing a element from a Multi-Dimensional list
For
Geeks
91
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
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
95
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

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 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
For
02
List with the use of 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____75____________________________________________________________________________________________________________________________________

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
Accessing element using negative indexing
Geeks
For
21

Keluaran

Blank 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
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']
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
Geeks
04__________________________757575.00________________________________________________________________________________________________

Accessing element using negative indexing
Geeks
For
40
Accessing element using negative indexing
Geeks
For
41
List with the use of 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
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']
4
Accessing element using negative indexing
Geeks
For
45
List with the use of 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
Geeks
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
For
49
List with the use of 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________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
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

Accessing element using negative indexing
Geeks
For
_61

Accessing element using negative indexing
Geeks
For
_62

Accessing a element from the list
Geeks
Geeks
4
Accessing element using negative indexing
Geeks
For
64
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Accessing a element from the list
Geeks
Geeks
4
Accessing element using negative indexing
Geeks
For
64
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
10
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing element using negative indexing
Geeks
For
73
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Keluaran

Blank 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
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']
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
Geeks
04__________________________757575.00________________________________________________________________________________________________

Accessing element using negative indexing
Geeks
For
40
Accessing element using negative indexing
Geeks
For
41
List with the use of 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
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']
4
Accessing element using negative indexing
Geeks
For
45
List with the use of 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
Geeks
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
For
49
List with the use of 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________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
Geeks
62
Accessing a element from the list
Geeks
Geeks
63
Accessing a element from the list
Geeks
Geeks
64
Accessing a element from the list
Geeks
Geeks
8
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
Geeks
12
Accessing a element from the list
Geeks
Geeks
69

Accessing a element from the list
Geeks
Geeks
_70
Accessing a element from the list
Geeks
Geeks
4
0
3
21

List with the use of 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
Geeks
8
0
3
24
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

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

Python3




Accessing a element from the list
Geeks
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']
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________76______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
Geeks
04
List with the use of 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
Geeks
_00_______4_______4_______8__5_____4

 

0
3
_43

0
3
_44

________14

List with the use of Numbers: 
[1, 2, 4, 4, 3, 3, 3, 6, 5]

List with the use of Mixed Values: 
[1, 2, 'Geeks', 4, 'For', 6, 'Geeks']
_48_______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
Geeks
8
0
3
49
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

0
3
_55

0
3
_56

0
3
_44

Accessing a element from the list
Geeks
Geeks
4
0
3
59
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
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']
_9
Accessing a element from the list
Geeks
Geeks
8
0
3
64
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

Keluaran

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
5

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 Iris.  

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
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']
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
0
3
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
0
3
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
0
3
78__________________54848484848.____54848

Accessing element using negative indexing
Geeks
For
40
0
3
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']
4
0
3
91
List with the use of 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
0
3
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
0
3
_________________________________________________________________________548

List with the use of 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
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

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
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']
2
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
04
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
18
Accessing a element from a Multi-Dimensional list
For
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']
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
Geeks
8
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
23
Accessing a element from a Multi-Dimensional list
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']
_9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
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
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']
2
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
12
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
Geeks
8
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
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']
_9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
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
Geeks
4
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
Geeks
8
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
51
Accessing a element from a Multi-Dimensional list
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']
_9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
26

Keluaran

Blank 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
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']
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
0
3
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
0
3
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
0
3
78__________________54848484848.____54848

Accessing element using negative indexing
Geeks
For
40
0
3
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']
4
0
3
91
List with the use of 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
0
3
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
0
3
_________________________________________________________________________548

List with the use of 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
Geeks
8
Accessing a element from a Multi-Dimensional list
For
Geeks
31
Accessing a element from a Multi-Dimensional list
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']
_9
Accessing a element from the list
Geeks
Geeks
8
Accessing a element from the list
Geeks
Geeks
4
Accessing a element from a Multi-Dimensional list
For
Geeks
0

 

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
Geeks
4
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
Geeks
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']
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
Geeks
8
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
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']
_9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
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
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']
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
Geeks
10
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']
4_______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________4______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
Geeks
8
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
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']
_9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
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
Geeks
4
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
Geeks
8
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
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']
_9
Enter elements: GEEKS FOR GEEKS
The list is: ['GEEKS', 'FOR', 'GEEKS']
26

Keluaran

Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
_7

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]
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
Geeks
61
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
Geeks
63
Accessing a element from the list
Geeks
Geeks
64
Accessing a element from the list
Geeks
Geeks
8
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
For
49
Accessing a element from a Multi-Dimensional list
For
Geeks
0
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
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
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.  

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]
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
Geeks
6

 

Accessing a element from the list
Geeks
Geeks
_61
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
Geeks
63
Accessing a element from the list
Geeks
Geeks
64
Accessing a element from the list
Geeks
Geeks
8
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
For
49
Accessing a element from the list
Geeks
Geeks
69

Accessing a element from the list
Geeks
Geeks
70
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

________36______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
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']
_9
Enter the size of list : 4
Enter the integer elements: 6 3 9 10
The list is: [6, 3, 9, 10]
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

  • 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 perantara

Baca 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” }

Apa itu daftar struktur data?

Apa itu Daftar? . Misalnya, list1 dan list2 yang ditampilkan di bawah berisi satu jenis data. Di sini, list1 memiliki bilangan bulat sedangkan list2 memiliki string. Daftar juga dapat menyimpan tipe data campuran seperti yang ditunjukkan pada daftar3 di sini. an ordered data structure with elements separated by a comma and enclosed within square brackets. For example, list1 and list2 shown below contains a single type of data. Here, list1 has integers while list2 has strings. Lists can also store mixed data types as shown in the list3 here.

Apa itu struktur dalam Python?

Struk didefinisikan menggunakan bahasa mini berdasarkan string format yang memungkinkan Anda menentukan susunan berbagai tipe data C seperti char , int , dan long serta varian unsignednya . Struk berseri jarang digunakan untuk merepresentasikan objek data yang dimaksudkan untuk ditangani murni di dalam kode Python. . Serialized structs are seldom used to represent data objects meant to be handled purely inside Python code.

Apa perbedaan antara daftar [. ] dan daftar?

li[. ] membuat salinan dari daftar asli. Tapi itu tidak merujuk ke daftar objek yang sama . Karenanya Anda tidak mengambil risiko mengubah daftar asli dengan mengubah salinan yang dibuat oleh li[. ]. Di sini list2 diubah dengan mengubah list1 tetapi list3 tidak berubah.

Bagaimana Anda membuat daftar struktur dengan Python?

Dalam Python kumpulan objek atau elemen disebut daftar. Ini lebih dikenal sebagai array dalam Javascript. Setiap elemen dalam daftar disebut item dan dapat dirujuk oleh indeks yang dimulai dengan 0 .

Bài mới nhất

Chủ Đề