Apa itu Variabel?
Variabel = tempat menyimpan data di memori komputer.
Contoh:
nama = "Ran"
umur = 16
tinggi = 170.5
is_student = True
Tipe Data Dasar
Tipe | Contoh |
---|---|
int | 5 , 100 , -3 |
float | 3.14 , -0.5 |
str | "halo" , 'dunia' |
bool | True , False |
Contoh Kode Lengkap:
# Variabel
nama = "Ran"
umur = 16
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)
Leave a Reply