بخشی از مجموعه

چندین نمونه کد

~1 دقیقه مطالعه • بروزرسانی ۱۲ مهر ۱۴۰۴

Program Overview

This Python program demonstrates how logical operations AND, OR, and NOT behave when applied to boolean values.
It converts the result of each operation into a numeric value: True → 1, False → 0.


Python Code:


# Define sample boolean values
a = True
b = False

# Logical operations and numeric conversion
and_result = int(a and b)
or_result = int(a or b)
not_result = int(not a)

# Display results
print("AND (True && False):", and_result)
print("OR  (True || False):", or_result)
print("NOT (!True):", not_result)

Sample Output:


AND (True && False): 0  
OR  (True || False): 1  
NOT (!True): 0

Step-by-Step Explanation:

- a and b returns Falseint(False) = 0
- a or b returns Trueint(True) = 1
- not a returns Falseint(False) = 0
- The int() function converts boolean results to numeric form


نوشته و پژوهش شده توسط دکتر شاهین صیامی