- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-Types.py
More file actions
Latest commit
60 lines (49 loc) · 766 Bytes
/
Copy path08-Types.py
File metadata and controls
60 lines (49 loc) · 766 Bytes
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
51
52
53
54
55
56
57
58
59
60
i : int
j : float
k : str
l : bool
m : None
# Python Data Types
i=5
j=3.14
k='abc'
l=True
m=None
print(type(i)) # <class 'int'>
print(type(j)) # <class 'float'>
print(type(k)) # <class 'str'>
print(type(l)) # <class 'bool'>
print(type(m)) # <class 'NoneType'>
# Type Conversion
# int to float
i=5
j=float(i)
print(j) # 5.0
# float to int
j=3.14
i=int(j)
print(i) # 3
# str to int
i='5'
j=int(i)
print(j) # 5
# str to float
i='3.14'
j=float(i)
print(j) # 3.14
# int to str
i=5
j=str(i)
print(j) # '5'
# float to str
i=3.14
j=str(i)
print(j) # '3.14'
# bool to int
i=True
j=int(i)
print(j) # 1
# bool to str
i=True
j=str(i)
print(j) # 'True'