Tutorial Python

RUMAH Python Pengenalan Python Python Memulai Sintaks Python Komentar Python Variabel Python Tipe Data Python Nomor Python Pengecoran Python String Python Python Boolean Operator Python Daftar Python Tuple Python Set Python Kamus Python Python Jika...Lain Python Sementara Loop Python Untuk Loop Fungsi Python Python Lambda Array Python Kelas/Objek Python Warisan Python Python Iterator Lingkup Python Modul Python Tanggal Python Python Matematika Python JSON Python RegEx Python PIP Python Coba...Kecuali Masukan Pengguna Python Pemformatan String Python

Penanganan Berkas

Penanganan File Python File Baca Python Python Tulis/Buat File Python Hapus File

Modul Python

Tutorial NumPy Panduan Panda Tutorial sip

Python Matplotlib

Pengantar Matplotlib Matplotlib Memulai Matplotlib Pyplot Merencanakan Matplotlib Penanda Matplotlib Garis Matplotlib Label Matplotlib Kotak Matplotlib Subplot Matplotlib Penyebaran Matplotlib Matplotlib Bar Histogram Matplotlib Bagan Pai Matplotlib

Pembelajaran mesin

Mulai Mode Median Rata-rata Standar Deviasi Persentil Distribusi Data Distribusi Data Normal Plot Pencar Regresi linier Regresi Polinomial Regresi Berganda Skala Kereta/Tes Pohon Keputusan

Python MySQL

MySQL Memulai MySQL Buat Basis Data MySQL Buat Tabel Sisipan MySQL MySQL Pilih MySQL Dimana MySQL Dipesan Oleh Hapus MySQL Tabel Drop MySQL Pembaruan MySQL Batas MySQL MySQL Bergabung

Python MongoDB

MongoDB Memulai MongoDB Buat Basis Data MongoDB Buat Koleksi Sisipan MongoDB Temukan MongoDB Permintaan MongoDB Sortir MongoDB Hapus MongoDB Koleksi Jatuhkan MongoDB Pembaruan MongoDB Batas MongoDB

Referensi Python

Ikhtisar Python Fungsi bawaan Python Metode String Python Metode Daftar Python Metode Kamus Python Metode Tuple Python Metode Set Python Metode File Python Kata Kunci Python Pengecualian Python Daftar Istilah Python

Referensi Modul

Modul Acak Modul Permintaan Modul Statistik Modul Matematika Modul cMath

Python Bagaimana caranya?

Hapus Duplikat Daftar Membalikkan String Tambahkan Dua Angka

Contoh Python

Contoh Python Kompilator Python Latihan Python Kuis Python Sertifikat Python

Tipe Data Python


Tipe Data Bawaan

Dalam pemrograman, tipe data merupakan konsep penting.

Variabel dapat menyimpan data dari tipe yang berbeda, dan tipe yang berbeda dapat melakukan hal yang berbeda.

Python memiliki tipe data berikut bawaan secara default, dalam kategori ini:

Jenis Teks: str
Jenis numerik: int, float, complex
Jenis Urutan: list, tuple, range
Jenis Pemetaan: dict
Setel Jenis: set, frozenset
Tipe Boolean: bool
Jenis Biner: bytes, bytearray, memoryview

Mendapatkan Tipe Data

Anda bisa mendapatkan tipe data objek apa pun dengan menggunakan type()fungsi:

Contoh

Cetak tipe data variabel x:

x = 5
print(type(x))

Mengatur Tipe Data

Di Python, tipe data diatur saat Anda menetapkan nilai ke variabel:

Example Data Type Try it
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 = range(6) range
x = {"name" : "John", "age" : 36} dict
x = {"apple", "banana", "cherry"} set
x = frozenset({"apple", "banana", "cherry"}) frozenset
x = True bool
x = b"Hello" bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview


Mengatur Jenis Data Tertentu

Jika Anda ingin menentukan tipe data, Anda dapat menggunakan fungsi konstruktor berikut:

Example Data Type Try it
x = str("Hello World") str
x = int(20) int
x = float(20.5) float
x = complex(1j) complex
x = list(("apple", "banana", "cherry")) list
x = tuple(("apple", "banana", "cherry")) tuple
x = range(6) range
x = dict(name="John", age=36) dict
x = set(("apple", "banana", "cherry")) set
x = frozenset(("apple", "banana", "cherry")) frozenset
x = bool(5) bool
x = bytes(5) bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview

Uji Diri Anda Dengan Latihan

Olahraga:

Contoh kode berikut akan mencetak tipe data x, tipe data apa itu?

x = 5
print(type(x))