A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_URI::$config is deprecated
Filename: core/URI.php
Line Number: 101
Backtrace:
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Router::$uri is deprecated
Filename: core/Router.php
Line Number: 127
Backtrace:
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$benchmark is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$hooks is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$config is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$log is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$utf8 is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$uri is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$exceptions is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$router is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$output is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$security is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$input is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$lang is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$load is deprecated
Filename: core/Controller.php
Line Number: 78
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$db is deprecated
Filename: core/Loader.php
Line Number: 396
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_DB_mysqli_driver::$failover is deprecated
Filename: database/DB_driver.php
Line Number: 371
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 132
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 292
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 166
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 235
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 315
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 356
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 282
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 289
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 304
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 314
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 315
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 316
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 317
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 375
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: drivers/Session_files_driver.php
Line Number: 108
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 110
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Session cannot be started after headers have already been sent
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$session is deprecated
Filename: core/Loader.php
Line Number: 1283
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$form_validation is deprecated
Filename: core/Loader.php
Line Number: 1283
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$m_data is deprecated
Filename: core/Loader.php
Line Number: 358
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 11
Function: model
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$benchmark is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$hooks is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$config is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$log is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$utf8 is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$uri is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$exceptions is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$router is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$output is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$security is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$input is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$lang is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$load is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$db is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$session is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$form_validation is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$m_data is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
alf-printing Digital-Printing dan Media Pembelajaran
Cepat, Berkualitas, dan Terjangkau
Indonesia
Algoritma Struktur Data Per 2
BAB I - Pengenalan Python
A. Pengenalan Python
Python merupakan bahasa pemrograman tingkat tinggi yang bersifat interpretatif,
multiplatform, dan multiguna, yang dikembangkan oleh Guido van Rossum.
Python dirancang dengan sintaks yang sederhana dan mudah dibaca sehingga
sangat cocok digunakan oleh pemula maupun programmer profesional.
Python banyak digunakan dalam berbagai bidang, antara lain pengembangan
aplikasi desktop (GUI), aplikasi web, aplikasi mobile, Internet of Things (IoT),
game, data science, artificial intelligence, machine learning, hingga keamanan sistem.
Keunggulan Python terletak pada kesederhanaan kode dan kemudahan implementasi,
sehingga programmer dapat lebih fokus pada pengembangan logika aplikasi
dibandingkan dengan permasalahan sintaks.
print("Python itu sangat simple broo")
Dengan perintah print(), kita dapat menampilkan teks atau data ke layar.
Python juga tidak mewajibkan penggunaan tanda titik koma (;) di akhir baris perintah.
B. Instalasi Python
Sebelum menggunakan Python, pengguna harus menginstal Python terlebih dahulu
pada sistem operasi komputer. Saat ini Python memiliki dua versi utama, yaitu
Python 2 dan Python 3.
Python 2 (versi terakhir 2.7.17, sudah tidak dikembangkan)
Python 3 (versi terbaru dan direkomendasikan)
Dalam materi ini digunakan Python versi 3.8.0 sebagai versi stabil.
File instalasi Python dapat diunduh melalui situs resmi berikut:
https://www.python.org/downloads/
Setelah instalasi selesai, Python menyediakan IDE bawaan bernama IDLE
(Integrated Development and Learning Environment) yang dapat digunakan
untuk menulis dan menjalankan program Python.
C. Integrated Development Environment (IDE) Python
Integrated Development Environment (IDE) adalah perangkat lunak yang menyediakan
berbagai fasilitas untuk mempermudah proses pengembangan program, seperti
editor kode, debugger, dan tools pendukung lainnya.
Meskipun program Python dapat ditulis menggunakan text editor biasa,
penggunaan IDE sangat disarankan bagi pemula karena lebih mudah digunakan
dan membantu meminimalkan kesalahan.
Beberapa IDE dan Framework Python Populer:
Web Development: Django, Flask, Pyramid, Bottle, Tornado, web2py
GUI Development: Tkinter, PyQt, PySide, Kivy, wxPython
Scientific & Numeric: SciPy, Pandas, IPython
Software Development: Buildbot, Trac, Roundup
System Administration: Ansible, Salt, OpenStack
D. Tipe Data Python
Tipe data merupakan jenis nilai yang dapat disimpan di dalam memori komputer
untuk diolah oleh program. Python memiliki tipe data yang dinamis,
sehingga tidak memerlukan deklarasi tipe data secara eksplisit.
Integer (int)
Float (float)
String (str)
Boolean (bool)
List
Tuple
Dictionary
Set
Pada bagian selanjutnya akan dilakukan praktik penggunaan tipe data Python
untuk memperdalam pemahaman.
E. Variabel Python
Variabel adalah lokasi memori yang digunakan untuk menyimpan nilai atau data
sementara selama program dijalankan. Nilai yang tersimpan dalam variabel
dapat berubah sesuai dengan proses atau operasi yang dilakukan.
Variabel sangat penting dalam pemrograman karena memungkinkan program
menyimpan dan mengolah data secara dinamis.
Aturan Penulisan Variabel Python:
Karakter pertama harus berupa huruf atau garis bawah (_)
Karakter selanjutnya dapat berupa huruf, angka, atau garis bawah (_)
Nama variabel bersifat case-sensitive
Tidak boleh menggunakan kata kunci Python
nama = "Budi"
umur = 20
_nilai = 85
namaDepan = "Andi"
Contoh perbedaan case-sensitive:
namaDepan = "Andi"
namadepan = "Budi"
Kedua variabel tersebut dianggap berbeda oleh Python.
Perbedaan List dan Dictionary Python
Perbedaan List dan Dictionary Bahasa Pemrograman Python
1. List
List adalah struktur data dalam Python yang digunakan untuk
menyimpan sekumpulan data secara berurutan (ordered). Data pada list
diakses menggunakan indeks (nomor urut) yang dimulai dari angka 0.
Ciri-ciri List:
Menggunakan tanda kurung siku [ ]
Data tersusun secara berurutan
Diakses menggunakan indeks
Data dapat diubah (mutable)
Cocok untuk menyimpan data sejenis
Contoh List:
nama_siswa = ["Andi", "Budi", "Citra"]
Mengakses Data List:
print(nama_siswa[0]) # Output: Andi
2. Dictionary
Dictionary adalah struktur data Python yang menyimpan data
dalam bentuk pasangan key dan value . Data pada dictionary
diakses menggunakan key, bukan indeks.
Ciri-ciri Dictionary:
Menggunakan tanda kurung kurawal { }
Data disimpan dalam bentuk key-value
Diakses menggunakan key
Data dapat diubah (mutable)
Cocok untuk data yang memiliki atribut
Contoh Dictionary:
siswa = {
"nama": "Andi",
"umur": 17,
"nilai": 85
}
Mengakses Data Dictionary:
print(siswa["nama"]) # Output: Andi
3. Perbedaan Utama List dan Dictionary
Aspek
List
Dictionary
Bentuk Data
Kumpulan data berurutan
Pasangan key dan value
Cara Akses
Menggunakan indeks
Menggunakan key
Penulisan
[ ]
{ }
Kegunaan
Data sejenis
Data dengan atribut
4. Kapan Menggunakan List atau Dictionary?
Gunakan List jika:
Menyimpan banyak data sejenis
Data perlu diakses berdasarkan urutan
Gunakan Dictionary jika:
Data memiliki keterangan atau atribut
Data perlu diakses berdasarkan nama
Dalam praktik algoritma dan struktur data, List dan Dictionary
sering dikombinasikan untuk membangun sistem manajemen data.
5. Contoh Kombinasi List dan Dictionary
data_siswa = [
{"nama": "Andi", "nilai": 85},
{"nama": "Budi", "nilai": 90}
]
Struktur ini umum digunakan dalam pembuatan algoritma pencarian,
pengurutan, dan pengolahan data.