MasPutraWae

Python

Python - Tabel Tipe Data Lengkap

Grouping Data Type Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool Binary Types: bytes, bytearray, memoryview None Type: NoneType Setting the Data Type Dalam Python, tipe data ditetapkan saat Anda menetapkan nilai ke variabel: Example Data Type x = "Hello World" str x = 20 int x = 20.5 float x = 1j complex x = ["apple", "banana", "cherry"] list x = ("apple", "banana", "cherry") tuple x = …

Python - Manipulasi String

Di Python, manipulasi string artinya semua cara buat mengubah, memproses, atau mengambil bagian tertentu dari teks (string). Berikut rangkuman lengkapnya 👇 1. Dasar: Membuat dan Mengakses String teks = "Halo Dunia" print(teks[0]) # H print(teks[-1]) # a print(teks[5:10]) # Dunia ➡️ Bisa pakai indexing dan slicing untuk ambil sebagian teks. 2. Menggabungkan dan Mengulang a = "Halo" b = "Putra" print(a + " " + b) # Halo Putra print(a * 3) # HaloHaloHalo 3. Mengubah Huruf s = "python" …

Python - Error KeyboardInterrupt

Ctrl+C di terminal jika program python sedang berjalan maka akan menghasilkan error, untuk mencoba bisa buat seperti ini def main(): while True: input("===== Coba Tekan CTRL + C") try: main() except KeyboardInterrupt as e: print(e) Atau jika ingin menangkap KeyboardInterrupt tapi dengan hasil yang lebih bersih agar saat keluar dari program tidak benar-benar memaksa, coba buat seperti ini import time def long_running_process(): try: print("Performing a long-running process. Press Ctrl+C to …