-
Notifications
You must be signed in to change notification settings - Fork 0
/
tipedata_casting.py
50 lines (42 loc) · 1.72 KB
/
tipedata_casting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# casting
# merubah tipe ke tipe lain
# INTEGER
print("=================INT============")
data_int = 9
print("data =", data_int, ",type =",type(data_int))
data_float = float(data_int)
data_str = str(data_int)
data_bool = bool(data_int) # akan false jika nilai int = 0 dan akan true jika nilai int -1
print("data =", data_float, "type =",type(data_float))
print("data =", data_str, "type =",type(data_str))
print("data =", data_bool, "type =",type(data_bool))
## FLOAT
print("=================FLOAT============")
data_float = 9.9
print("data =", data_float, "type =",type(data_float))
data_int = int(data_float)
data_str = str(data_float)
data_bool = bool(data_float) # akan false jika nilai int = 0 dan akan true jika nilai int -1
print("data =", data_int, "type =",type(data_int))
print("data =", data_str, "type =",type(data_str))
print("data =", data_bool, "type =",type(data_bool))
## BOOLEAN
print("=================BOOLEAN============")
data_bool = False;
print("data =", data_bool, "type =",type(data_bool))
data_int = int(data_bool)
data_str = str(data_bool)
data_float = bool(data_float) # akan false jika nilai int = 0 dan akan true jika nilai int -1
print("data =", data_int, "type =",type(data_int))
print("data =", data_str, "type =",type(data_str))
print("data =", data_float, "type =",type(data_float))
## STR
print("=================STR============")
data_str = "0";
print("data =", data_str, "type =",type(data_str))
data_int = int(data_str) # string harus angka
data_float = float(data_str) # string harus angka
data_bool = bool(data_str) # false jika string kosong
print("data =", data_int, "type =",type(data_int))
print("data =", data_float, "type =",type(data_float))
print("data =", data_bool, "type =",type(data_bool))