-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboolean.py
More file actions
49 lines (40 loc) · 1.26 KB
/
boolean.py
File metadata and controls
49 lines (40 loc) · 1.26 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
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 17 18:19:08 2023
@author: Teja Ram Pooniya
@Program: Topic: Boolean in Python How to Program
"""
"""
Description:
Booleans in Python are a data type that represent the two truth values:
True and False. Booleans are used to perform logical operations
and make decisions in your code.
Booleans are essential for creating conditional logic in your code.
They are used in if statements, loops, and functions to
control program flow based on certain conditions.
"""
# Boolean values
is_true = True
is_false = False
# Comparisons
x = 5
y = 10
result = x < y # result will be True
# Logical operators
logical_and = True and False # result will be False
logical_or = True or False # result will be True
logical_not = not True # result will be False
# Conditional statements
if x < y:
print("x is less than y")
else:
print("x is not less than y")
# Using booleans in loops
while is_true:
print("This will keep running as long as is_true is True")
is_true = False # Change is_true to False to exit the loop
# Using booleans in functions
def is_even(number):
return number % 2 == 0
print(is_even(4)) # Output: True
print(is_even(7)) # Output: False