Python – Variabel & Tipe Data Dasar

Tujuan Hari Ini:

  • Mengenal variabel di Python
  • Mengenal tipe data dasar:
    • int (angka bulat)
    • float (angka desimal)
    • str (teks/string)
    • bool (boolean: True / False)

Apa itu Variabel?

Variabel = tempat menyimpan data di memori komputer.

Contoh:

nama = "Ran"
umur = 25
tinggi = 170.5
is_student = True

Tipe Data Dasar

TipeContoh
int5, 100, -3
float3.14, -0.5
str"halo", 'dunia'
boolTrue, False

Contoh Kode Lengkap:

# Variabel
nama = "Ran"
umur = 25
tinggi = 170.5
is_student = True

# Menampilkan tipe data
print(type(nama))     # <class 'str'>
print(type(umur))     # <class 'int'>
print(type(tinggi))   # <class 'float'>
print(type(is_student))  # <class 'bool'>

# Menampilkan isi variabel
print("Nama saya:", nama)
print("Umur saya:", umur, "tahun")
print("Tinggi saya:", tinggi, "cm")
print("Apakah saya pelajar?", is_student)

E-Book Learn Programming For The AI Era : https://lynk.id/axolumedigital/vNkVBKb

Be the first to comment

Leave a Reply

Your email address will not be published.


*