Fungsi Type()
Deskripsi
Fungsi type()
berfungsi untuk mengetahui jenis/tipe data dari suatu objek.
Sintaks
type(object)
type(name, bases, dict)
Parameter
Fungsi type()
memiliki beberapa parameter, yaitu:
- object – objek yang hendak dicari tahu tipenya
- name – nama kelas, sebagai atribut __name__
- bases – tuple base class, sebagai atribut __bases__
- dict – dictionary dari body class, sebagai atribut __dict__
Nilai Kembalian
Fungsi type()
mengembalikan tipe dari objek
Contoh
type(1)
type([1, 3])
o1 = type('X', (object,), dict(a='Foo', b=12))
print(type(o1))
print(vars(o1))
class test:
a = 'Foo'
b = 12
o2 = type('Y', (test,), dict(a='Foo', b=12))
print(type(o2))
print(vars(o2))
Output
{'b': 12, 'a': 'Foo', '__dict__':, '__doc__': None, '__weakref__': }
{'b': 12, 'a': 'Foo', '__doc__': None}