Repository navigation
Expand file tree
/
Copy path015-Boolean-to-Integer-Type-Casting.py
More file actions
104 lines (86 loc) · 4.63 KB
/
Copy path015-Boolean-to-Integer-Type-Casting.py
File metadata and controls
104 lines (86 loc) · 4.63 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
===============================================================================
Boolean to Integer Type Casting
===============================================================================
Program Description:
--------------------
This program demonstrates how to convert a Boolean data type into an
Integer data type using the int() function.
In Python:
True is converted to 1
False is converted to 0
Example:
True ---> 1
False ---> 0
Author : Shaik Mahaboob Basha
Repository : 13-Python
File Name : 15-Boolean-to-Integer-Type-Casting.py
===============================================================================
"""
# -----------------------------------------------------------------------------
# Creating a Boolean variable with the value True.
# -----------------------------------------------------------------------------
boolean_value_true = True
# boolean_value_true stores the Boolean value True.
# -----------------------------------------------------------------------------
# Displaying the original Boolean value.
# -----------------------------------------------------------------------------
print("Original Boolean Value :", boolean_value_true)
# Output: Original Boolean Value : True
# -----------------------------------------------------------------------------
# Displaying the data type of the original variable.
# -----------------------------------------------------------------------------
print("Original Data Type :", type(boolean_value_true))
# Output: Original Data Type : <class 'bool'>
# -----------------------------------------------------------------------------
# Converting the Boolean value True into an integer using int().
# True is converted to 1.
# -----------------------------------------------------------------------------
integer_value_true = int(boolean_value_true)
# integer_value_true stores the integer value 1.
# -----------------------------------------------------------------------------
# Displaying the converted integer value.
# -----------------------------------------------------------------------------
print("Converted Integer Value :", integer_value_true)
# Output: Converted Integer Value : 1
# -----------------------------------------------------------------------------
# Displaying the data type after conversion.
# -----------------------------------------------------------------------------
print("Converted Data Type :", type(integer_value_true))
# Output: Converted Data Type : <class 'int'>
# -----------------------------------------------------------------------------
# Creating another Boolean variable with the value False.
# -----------------------------------------------------------------------------
boolean_value_false = False
# boolean_value_false stores the Boolean value False.
# -----------------------------------------------------------------------------
# Displaying the original Boolean value.
# -----------------------------------------------------------------------------
print("Original Boolean Value :", boolean_value_false)
# Output: Original Boolean Value : False
# -----------------------------------------------------------------------------
# Displaying the data type of the original variable.
# -----------------------------------------------------------------------------
print("Original Data Type :", type(boolean_value_false))
# Output: Original Data Type : <class 'bool'>
# -----------------------------------------------------------------------------
# Converting the Boolean value False into an integer using int().
# False is converted to 0.
# -----------------------------------------------------------------------------
integer_value_false = int(boolean_value_false)
# integer_value_false stores the integer value 0.
# -----------------------------------------------------------------------------
# Displaying the converted integer value.
# -----------------------------------------------------------------------------
print("Converted Integer Value :", integer_value_false)
# Output: Converted Integer Value : 0
# -----------------------------------------------------------------------------
# Displaying the data type after conversion.
# -----------------------------------------------------------------------------
print("Converted Data Type :", type(integer_value_false))
# Output: Converted Data Type : <class 'int'>
# -----------------------------------------------------------------------------
# Displaying an important note about Boolean-to-Integer conversion.
# -----------------------------------------------------------------------------
print("Note: True converts to 1 and False converts to 0.")
# Output: Note: True converts to 1 and False converts to 0.